c++ – How to create a template alias?

Question:

I want to check the type of an iterator in some way:

template <typename It, typename T>
using is = std::is_same<std::iterator_traits<It>::iterator_category, T>::value;

And then use this case in asserts ( RanIt is a template type):

static_assert(is<RanIt, std::random_access_iterator_tag>, "random access required");

What am I doing wrong?

Answer:

Either replace using with constexpr bool , or remove ::value from the definition and move it to the checkpoint.

using is not a constant, but an alias. Can be a synonym for the type within which the constant value is defined, but cannot itself be a constant.

Scroll to Top