Function that takes an STL iterator over ANY container of a elements of a specific type

前端 未结 5 1968
刺人心
刺人心 2021-02-12 19:12

How would I define a function that takes as input an iterator over any type of STL container, but only to those of a specific templated type. For example:

Any iterator o

5条回答
  •  旧巷少年郎
    2021-02-12 19:39

    You only want to iterate over containers of my_special_type? In that case:

    template 
    struct enable_if;
    
    template 
    struct enable_if
    {
        typedef T type;
    };
    
    template 
    struct is_same
    {
        enum {value = false};
    };
    
    template 
    struct is_same
    {
        enum {value = true};
    };
    
    template 
    typename enable_if::value,
                      void>::type
    function(Iter begin, Iter end)
    {
        // ...
    }
    

提交回复
热议问题