struct Yes { char c[2]; };
struct No { char c; };
- template<size_t s>
+ template<typename T>
+ static No f(...);
+
+ template<typename C, typename T>
struct Evaluate
{
- enum { value = (s==sizeof(Yes)) };
+ enum { value = (sizeof(C::template f<T>(0))==sizeof(Yes)) };
};
};
// Generic operators using stringstream
-template<typename T>
-struct HasFormattedOutput: Sfinae
+struct CheckFormattedOutput: Sfinae
{
static std::ostream &s;
- static T &v;
-
- /* The expression must depend on the template parameter, or the compiler
- will give an error. */
- template<typename U>
- static Yes f(int (*)[sizeof(s<<HasFormattedOutput<U>::v)]);
- template<typename U>
- static No f(...);
-
- enum { value = Evaluate<sizeof(f<T>(0))>::value };
+ template<typename T>
+ static Yes f(int (*)[sizeof(s<<T())]);
+ using Sfinae::f;
};
-template<typename T>
-struct HasFormattedInput: Sfinae
+struct CheckFormattedInput: Sfinae
{
static std::istream &s;
- static T &v;
-
- template<typename U>
- static Yes f(int (*)[sizeof(s>>HasFormattedOutput<U>::v)]);
- template<typename U>
- static No f(...);
-
- enum { value = Evaluate<sizeof(f<T>(0))>::value };
+ template<typename T>
+ static Yes f(int (*)[sizeof(s>>reinterpret_cast<T &>(s))]);
+ using Sfinae::f;
};
+template<typename T> struct HasFormattedOutput: Sfinae::Evaluate<CheckFormattedOutput, T> { };
+template<typename T> struct HasFormattedInput: Sfinae::Evaluate<CheckFormattedInput, T> { };
+
template<typename T>
typename EnableIf<HasFormattedOutput<T>::value, void>::Yes