X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fstrings%2Flexicalcast.h;h=4f54a8515df8e2806cc118e0a4d982b88ff0a5c2;hp=2ed0621291858c0d0f4d40fb37036fd5decc5700;hb=641a71730a0135fe647f6a230e9704d8b677f2c5;hpb=ea901644ac2d36256d1f38c7a3adaaee787fe1b9 diff --git a/source/strings/lexicalcast.h b/source/strings/lexicalcast.h index 2ed0621..4f54a85 100644 --- a/source/strings/lexicalcast.h +++ b/source/strings/lexicalcast.h @@ -93,53 +93,42 @@ void operator>>(const LexicalConverter &, std::string &); // Generic operators using stringstream -template -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 - static Yes f(int (*)[sizeof(s<::v)]); - template - static No f(...); - - enum { value = Evaluate(0))>::value }; + template + static Yes f(int (*)[sizeof(s<(s))]); + using Sfinae::f; }; -template -struct HasFormattedInput: Sfinae +struct CheckFormattedInput: Sfinae { static std::istream &s; - static T &v; - - template - static Yes f(int (*)[sizeof(s>>HasFormattedOutput::v)]); - template - static No f(...); - - enum { value = Evaluate(0))>::value }; + template + static Yes f(int (*)[sizeof(s>>reinterpret_cast(s))]); + using Sfinae::f; }; +template struct HasFormattedOutput: Sfinae::Evaluate { }; +template struct HasFormattedInput: Sfinae::Evaluate { }; + template -typename EnableIf::value, void>::Yes +typename std::enable_if::value>::type operator<<(LexicalConverter &c, const T &v) { std::ostringstream ss; - ss< -typename EnableIf::value, void>::Yes +typename std::enable_if::value>::type 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 { LexicalConverter conv(s, f); T result; - conv>>result; + conv >> result; return result; } }; @@ -168,7 +157,7 @@ struct LexicalCast static std::string cast(const F &v, const Fmt &f = Fmt()) { LexicalConverter conv(f); - conv< static std::string cast(const std::string &v, const Fmt &f = Fmt()) { LexicalConverter conv(f); - conv<