How can I create a concept that tests for specialization?

Hi,

I want to create a concept that can only be applied to std::vector<T> for any T...

Some predicate like is_specialization_of ...

Thanks



I found an answer using this:


1
2
3
4
5
template<typename T>
constexpr bool is_a_vector = std::_Is_specialization<T, std::vector>::value;

template<typename T>
concept is_vector = is_a_vector<T>;





Last edited on
std::_Is_specialization isn't part of the C++ standard. It seems to be only available as part of VS C++ for internal usage (in type_traits). Starting with a _ is a marker that it may not be standard.

See https://stackoverflow.com/questions/31762958/check-if-class-is-a-template-specialization

Last edited on
There is a proposal to make std::is_specialization_of an official part of C++

https://open-std.org/JTC1/SC22/WG21/docs/papers/2020/p2098r1.pdf
Maybe in C++26...
Topic archived. No new replies allowed.