]> git.tdb.fi Git - libs/core.git/blobdiff - source/strings/lexicalcast.h
Fix formatted output operator detection in lexicalcast.h
[libs/core.git] / source / strings / lexicalcast.h
index 2ed0621291858c0d0f4d40fb37036fd5decc5700..22b45e88c55eef60e433b6253d0070b77c9242a5 100644 (file)
@@ -93,43 +93,32 @@ void operator>>(const LexicalConverter &, std::string &);
 
 // 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<<reinterpret_cast<const T &>(s))]);
+       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
 operator<<(LexicalConverter &c, const T &v)
 {
        std::ostringstream ss;
-       ss<<c.get_fmt()<<v;
+       ss << c.get_fmt() << v;
        c.result(ss.str());
 }
 
@@ -139,7 +128,7 @@ operator>>(const LexicalConverter &c, T &v)
 {
        std::istringstream ss(c.get());
        ss.setf(std::ios_base::fmtflags(0), std::ios_base::skipws);
-       ss>>v;
+       ss >> v;
        if(ss.fail() || !ss.eof())
                throw lexical_error("conversion failure");
 }
@@ -157,7 +146,7 @@ struct LexicalCast<T, std::string>
        {
                LexicalConverter conv(s, f);
                T result;
-               conv>>result;
+               conv >> result;
                return result;
        }
 };
@@ -168,7 +157,7 @@ struct LexicalCast<std::string, F>
        static std::string cast(const F &v, const Fmt &f = Fmt())
        {
                LexicalConverter conv(f);
-               conv<<v;
+               conv << v;
                return conv.get();
        }
 };
@@ -179,7 +168,7 @@ struct LexicalCast<std::string, std::string>
        static std::string cast(const std::string &v, const Fmt &f = Fmt())
        {
                LexicalConverter conv(f);
-               conv<<v;
+               conv << v;
                return conv.get();
        }
 };