yue*_*ngz 1 c++ templates sfinae type-traits c++11
我正在编写一个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) };
};
Run Code Online (Sandbox Code Playgroud)
如何在std :: enable_if中同时使用std :: is_pointer和has_const_iterator,或者如何编写可以匹配指向集合类型的指针的新类型特征?谢谢.
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> {};
Run Code Online (Sandbox Code Playgroud)
演示.