How can I create a concept that tests for specialization?

Sep 27, 2022 at 8:16pm
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



Sep 27, 2022 at 8:48pm
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 Sep 27, 2022 at 9:51pm
Sep 28, 2022 at 9:11am
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 Sep 28, 2022 at 3:52pm
Sep 28, 2022 at 3:18pm
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
Sep 28, 2022 at 4:00pm
Maybe in C++26...
Topic archived. No new replies allowed.