C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Compiler support for is_specialization_of

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Tue, 26 Mar 2024 13:13:42 +0000
On Tue, 26 Mar 2024 at 12:40, Frederick Virchanza Gotham via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Looking at P2098r1:
>
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2098r1.pdf
>
> The given implementation works fine for specialisations of 'vector', but
> not for specialisations of 'array', as follows:
>
> #include <cstddef>
> #include <array>
> #include <type_traits>
> #include <vector>
>
> namespace std {
> template< class T , template<class...> class Primary >
> struct is_specialization_of : false_type {};
> template< template<class...> class Primary , class... Args >
> struct is_specialization_of< Primary<Args...>, Primary> : true_type {};
> }
>
> int main(void)
> {
> using std::is_specialization_of;
> static_assert( is_specialization_of< std::vector<int>, std::vector
> >::value );
> static_assert( is_specialization_of< std::array<int, 5>, std::array
> >::value );
> }
>
> Compiler output:
>
> a.cpp: In function 'int main()':
> a.cpp:22:73: error: type/value mismatch at argument 2 in template
> parameter list for 'template<class T, template<class ...> class Primary>
> struct std::is_specialization_of'
> a.cpp:22:73: note: expected a template of type 'template<class ...> class
> Primary', got 'template<class _Tp, long unsigned int _Nm> struct std::array'
>
> If 'is_specialization_of' is to be written into the Standard, shall it be
> worded that it requires compiler support to let it work with every template
> class (and not just the ones whose parameters are exclusively all types)?
> Or will the use of this feature be restricted to template classes whose
> parameters are all types?
>
> I'm talking something like:
>
> namespace std {
> template< class T , /* COMPILER_SUPPORT */ Primary >
> struct is_specialization_of : false_type {};
> template< /* COMPILER_SUPPORT */ Primary , class... Args >
> struct is_specialization_of< Primary<Args...>, Primary> : true_type {};
> }
>


I think
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2989r1.pdf is the
latesty work in this space.

Received on 2024-03-26 13:15:01