我正在编写一个 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::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> {};
Demo .
关于c++ - 类型特征以匹配指向集合的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26312262/