]> git.tdb.fi Git - libs/core.git/blobdiff - source/strings/lexicalcast.h
Simplify the SFINAE construct a bit
[libs/core.git] / source / strings / lexicalcast.h
index 2ed0621291858c0d0f4d40fb37036fd5decc5700..13eab45f0b81c9311381f43f880caf2abb5fcf5b 100644 (file)
@@ -93,36 +93,25 @@ void operator>>(const LexicalConverter &, std::string &);
 
 // Generic operators using stringstream
 
 
 // Generic operators using stringstream
 
-template<typename T>
-struct HasFormattedOutput: Sfinae
+struct CheckFormattedOutput: Sfinae
 {
        static std::ostream &s;
 {
        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 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
 
 template<typename T>
 typename EnableIf<HasFormattedOutput<T>::value, void>::Yes