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

前端 未结 10 1333
不知归路
不知归路 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 14:49

    Actually, after some trial and error I found it's quite simple:

    template
    struct is_vector > {
      static bool const value = true;
    };
    

    I'd still like to know how to write a more general is_container. Do I have to list all types by hand?

提交回复
热议问题