Explanation:
Checking for the presence of a special parameter in the template is easy (using this).
The following code checks if char operator[] exists in Type or not:
template <class Type> class HasStringOperator { template <typename T, T> struct TypeCheck; typedef char Yes; typedef long No; template <typename T> struct operator_{ typedef char (T::*fptr)(int); }; template <typename T> static Yes HasOperator(TypeCheck< typename operator_<T>::fptr, &T::operator[] >*); template <typename T> static No HasOperator(...); public: static bool const value = (sizeof(HasOperator<Type>(0)) == sizeof(Yes)); };
ideone
Problem:
Now I want to check if all my variational pattern parameters have this operator. I cannot figure out how to send them one by one to HasStringOperator and check the whole result.
template < class... Word> class Sentence { static_assert(Do all of Words have 'char operator[]'?); };
What should I do?
c ++ function c ++ 11 templates variadic-templates
Omid
source share