C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Compiler support for is_specialization_of

From: Gašper Ažman <gasper.azman_at_[hidden]>
Date: Wed, 27 Mar 2024 00:50:57 +0900
Has been suggested before. Might still be a good idea, but in general
conveys the wrong thing.

On Tue, Mar 26, 2024, 23:14 Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
wrote:

> One thing intrigues me, why use `univeral tempalte` and not use `using`
> keyword?
> As using was not allowed in this context,
> having overlapping meaning, it is shorten.
> Overall it would fit nicely in this spot.
>
> wt., 26 mar 2024 o 14:29 Gašper Ažman via Std-Proposals
> <std-proposals_at_[hidden]> napisał(a):
> >
> > That's correct. We are hoping to catch c++26.
> >
> > On Tue, Mar 26, 2024, 22:15 Jonathan Wakely via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
> >>
> >>
> >>
> >> 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.
> >>
> >>
> >> --
> >> Std-Proposals mailing list
> >> Std-Proposals_at_[hidden]
> >> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
> >
> > --
> > Std-Proposals mailing list
> > Std-Proposals_at_[hidden]
> > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2024-03-26 15:51:09