C++ templates: how to determine if a type is suitable for subclassing

前端 未结 1 1118
故里飘歌
故里飘歌 2020-12-19 00:13

Let\'s say I have some templated class depending on type T. T could be almost anything: int, int*, pair

1条回答
  •  别那么骄傲
    2020-12-19 01:04

    You want to determine whether it is a non-union class. There is no way known to me to do that (and boost hasn't found a way either). If you can live with union cases false positives, you can use a is_class.

    template struct void_ { typedef void type; };
    
    template
    struct is_class { static bool const value = false; };
    
    template
    struct is_class::type> { 
      static bool const value = true; 
    };
    

    Boost has an is_union that uses compiler-specific builtins though, which will help you here. is_class (which boost also provides) combined with is_union will solve your problem.

    0 讨论(0)
提交回复
热议问题