2014-10-11 35 views
1

我正在寫一個SFINAE匹配的類,它可以匹配指向集合類型的指針。類型特徵以匹配集合的指針

目前,我們的std :: is_pointer,我已經寫了:

// SFINAE test for const_iterator for member type 
template <typename T> 
class has_const_iterator{ 
private: 
    typedef char True; 
    typedef long False; 

    template <typename C> static True test(typename C::const_iterator*) ; 
    template <typename C> static False test(...); 

public: 
    enum { value = sizeof(test<T>(0)) == sizeof(char) }; 
}; 

我如何可以同時使用的std :: is_pointer和has_const_iterator在一個std :: enable_if或者我怎麼能寫一個新的類型特質,可以匹配指向集合類型的指針嗎?謝謝。

回答

5
template<class T> 
struct is_pointer_to_collection 
    : std::integral_constant<bool, std::is_pointer<T>::value 
      && has_const_iterator<typename std::remove_pointer<T>::type>::value> {}; 

Demo