How to write a type trait `is_container` or `is_vector`?

前端 未结 10 1349
不知归路
不知归路 2020-11-27 14:11

Is it possible to write a type trait whose value is true for all common STL structures (e.g., vector, set, map, ...)?

To get s

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 15:06

    In our project we still didn't manage to migrate to compiler supporting C++11, so for type_traits of container objects I had to wrote a simple boost style helper:

    template struct is_std_container: boost::false_type {};
    template 
    struct is_std_container >: boost::true_type {};
    template 
    struct is_std_container >: boost::true_type {};
    template 
    struct is_std_container >: boost::true_type {};
    template 
    struct is_std_container >: boost::true_type {};
    template 
    struct is_std_container >: boost::true_type {};
    
    template struct is_std_sequence: boost::false_type {};
    template 
    struct is_std_sequence >: boost::true_type {};
    template 
    struct is_std_sequence >: boost::true_type {};
    template 
    struct is_std_sequence >: boost::true_type {};
    

提交回复
热议问题