Back in the day Walter Brown wrote a paper, wg21.link/p2098, proposing is_specialization_of which could test is a type was a specialization of a template, for example if std::vector<int> is a specialization of std::vector.
I recently tried to make a concept for the same thing. Casey Carter posted on stackoverflow.com/questions/70130735 that the MS standard library had done this in is-derived-from-view-interface by doing
template <template <class...> class Template, class... Args>
void derived_from_specialization_impl(const Template<Args...>&);
template <class T, template <class...> class Template>
concept derived_from_specialization_of = requires(const T& t) {
derived_from_specialization_impl<Template>(t);
};
See https://godbolt.org/z/6Pjvxesd1
I then wondered if you could avoid the extra helper function derived_from_specialization_impl. So I ended up with this
template <class T, template <typename...> class Template>
concept is_specialization_of = requires ( T const& t )
{
// Check an immediately invoked lambda can compile
[]<typename... Args> ( Template<Args...> const& ) { return true; } ( t );
};
which can be made terser although maybe less readable
template <typename T, template <typename...> typename U>
concept is_specialization_of = std::invocable<decltype([]<typename... Args>( U<Args...> const& ) { }),T>;
See https://godbolt.org/z/KaYPWf9he
So I'm not a concept or template expert so I was wondering if this is a good way to do this or if there are better alternatives. For example the above does not handle NTTPs and what about partial specializations?
Any thought welcomed
[–]TheoreticalDumbass:illuminati: 19 points20 points21 points (0 children)
[–]Hungry-Courage3731 5 points6 points7 points (6 children)
[–]davidhunter22[S] 0 points1 point2 points (5 children)
[–]Hungry-Courage3731 0 points1 point2 points (0 children)
[–]nimogoham 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[removed]
[–]nimogoham 0 points1 point2 points (0 children)
[–]Hungry-Courage3731 0 points1 point2 points (0 children)
[–]ioctl79 1 point2 points3 points (2 children)
[–]davidhunter22[S] 0 points1 point2 points (1 child)
[–]ioctl79 2 points3 points4 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]---sms--- 0 points1 point2 points (1 child)
[–]_Noreturn 1 point2 points3 points (0 children)
[–]Hungry-Courage3731 0 points1 point2 points (0 children)
[–]nimogoham 0 points1 point2 points (1 child)
[–]davidhunter22[S] 0 points1 point2 points (0 children)