I am trying to write a constexpr constant concisely using C++20 features.
#include <utility>
template <template <typename T, T ... Ints> std::integer_sequence<T, Ints...> I>
static constexpr long pow10_helper = ((Ints, 10) * ...);
template <std::size_t exp>
static constexpr long pow10 = pow10_helper< std::make_index_sequence<exp> >;
static_assert(pow10<3> == 1000);
but it is not compiling neither on GCC nor clang.
Is it possible to specify template non-type template parameters? Alternatively it is possible to write it recursively, but it would be nice to know if it is possible to write it like above.
Note that this question looks similar to Template template non-type parameter but the non-type template parameter is placed in the nested template parameter list instead of on the primary parameter list.
You cannot directly reference arguments to template template parameters. They are not in scope. But you could do something like this:
That being said, there are simpler ways of implementing
pow10
: