How to test if type is specialization of template with non-type parameters?

前端 未结 2 1827
眼角桃花
眼角桃花 2021-01-02 09:26

I was wondering if there was any solution to find if a type was a specialization of a template that takes non-type parameters without specifying every type ?

For ins

2条回答
  •  不知归路
    2021-01-02 09:35

    If you can modify F and there are no other restrictions you haven't mentioned, the easiest solution would be to add a unique base class:

    #include 
    #include 
    
    struct unique_F_base {};
    
    template
    struct F : unique_F_base
    {
    };
    
    template
    using is_F = std::is_base_of;
    
    int main()
    {
        static_assert( !is_F< int >::value, "Oops" );
        static_assert( is_F< F >::value, "Oops" );
    }
    

提交回复
热议问题