From: Mikko Rasa Date: Fri, 24 May 2019 16:57:22 +0000 (+0300) Subject: Simplify the SFINAE construct a bit X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e83bcaa01b98b600171886ff6b06d884385dd0ed;p=libs%2Fcore.git Simplify the SFINAE construct a bit More of the common stuff is now stored in the helper struct. --- diff --git a/source/core/meta.h b/source/core/meta.h index a13f5cb..d6ca359 100644 --- a/source/core/meta.h +++ b/source/core/meta.h @@ -43,10 +43,13 @@ struct Sfinae struct Yes { char c[2]; }; struct No { char c; }; - template + template + static No f(...); + + template struct Evaluate { - enum { value = (s==sizeof(Yes)) }; + enum { value = (sizeof(C::template f(0))==sizeof(Yes)) }; }; }; diff --git a/source/strings/lexicalcast.h b/source/strings/lexicalcast.h index 2ed0621..13eab45 100644 --- a/source/strings/lexicalcast.h +++ b/source/strings/lexicalcast.h @@ -93,36 +93,25 @@ 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< -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