detecting typedef at compile time (template metaprogramming)

后端 未结 4 1230
悲&欢浪女
悲&欢浪女 2021-02-03 10:06

I am currently doing some template metaprogramming. In my case I can handle any \"iteratable\" type, i.e. any type for which a typedef foo const_iterator exists in

4条回答
  •  孤独总比滥情好
    2021-02-03 10:48

    If you simply want if a given type contains const_iterator then following is a simplified version of your code:

    template
    struct void_ { typedef void type; };
    
    template
    struct Foo {};
    
    template
    struct Foo ::type> {
          void do_stuff(){ ... }
    };
    

    See this answer for some explanation of how this technique works.

提交回复
热议问题