From: Mikko Rasa Date: Sun, 29 Aug 2021 13:46:48 +0000 (+0300) Subject: Deprecate various meta-programming constructs in favor of std ones X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=commitdiff_plain;h=641a71730a0135fe647f6a230e9704d8b677f2c5 Deprecate various meta-programming constructs in favor of std ones --- diff --git a/source/core/meta.h b/source/core/meta.h index 6998c5d..3537301 100644 --- a/source/core/meta.h +++ b/source/core/meta.h @@ -2,42 +2,46 @@ #define MSP_CORE_META_H_ #include +#include "attributes.h" namespace Msp { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" template -struct RemoveConst +struct DEPRECATED RemoveConst { typedef T Type; }; template -struct RemoveConst +struct DEPRECATED RemoveConst { typedef T Type; }; template -struct RemoveReference +struct DEPRECATED RemoveReference { typedef T Type; }; template -struct RemoveReference +struct DEPRECATED RemoveReference { typedef T Type; }; template -struct RemoveConstReference +struct DEPRECATED RemoveConstReference { typedef typename RemoveConst::Type>::Type Type; }; template -struct EnableIf; +struct DEPRECATED EnableIf; template -struct EnableIf +struct DEPRECATED EnableIf { typedef R Yes; }; template -struct EnableIf +struct DEPRECATED EnableIf { typedef R No; }; +#pragma GCC diagnostic pop /** diff --git a/source/core/variant.h b/source/core/variant.h index 2dd9732..5109dbc 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -2,6 +2,7 @@ #define MSP_CORE_VARIANT_H_ #include +#include #include #include "meta.h" @@ -41,11 +42,11 @@ private: virtual bool value_equals(const StoreBase &s) const { return value_equals_(s); } template - typename EnableIf::value, bool>::Yes value_equals_(const StoreBase &s) const + typename std::enable_if::value, bool>::type value_equals_(const StoreBase &s) const { const Store *t = dynamic_cast *>(&s); return (t && t->data==data); } template - typename EnableIf::value, bool>::No value_equals_(const StoreBase &) const + typename std::enable_if::value, bool>::type value_equals_(const StoreBase &) const { return false; } }; @@ -54,7 +55,7 @@ private: public: Variant(): store(0) { } template - Variant(const T &v): store(new Store::Type>(v)) { } + Variant(const T &v): store(new Store::type>(v)) { } Variant(const Variant &v): store(v.store ? v.store->clone() : 0) { } ~Variant() { delete store; } @@ -62,7 +63,7 @@ public: Variant &operator=(const T &v) { delete store; - store = new Store::Type>(v); + store = new Store::type>(v); return *this; } @@ -75,9 +76,9 @@ public: private: template - Store::Type> *get_typed_store() const + Store::type> *get_typed_store() const { - typedef typename RemoveConst::Type NCT; + typedef typename std::remove_cv::type NCT; Store *s = dynamic_cast *>(store); if(!s) throw type_mismatch(typeid(T), (store ? store->type_id() : typeid(void))); @@ -100,7 +101,7 @@ public: template bool check_type() const { - return dynamic_cast::Type> *>(store)!=0; + return dynamic_cast::type> *>(store)!=0; } bool check_same_type(const Variant &v) const diff --git a/source/strings/lexicalcast.cpp b/source/strings/lexicalcast.cpp index 2fc4be3..1c1f720 100644 --- a/source/strings/lexicalcast.cpp +++ b/source/strings/lexicalcast.cpp @@ -10,12 +10,8 @@ namespace { using namespace Msp; -template -struct IsSigned -{ enum { result = !(static_cast(-1)>0) }; }; - /* Helper to avoid warnings about an unsigned type never being < 0 */ -template::result> +template::value> struct IsNegative { static bool eval(T v) { return v<0; } }; @@ -25,7 +21,7 @@ struct IsNegative /* Helper to avoid errors about ambiguous function calls since there are no overloads of abs for unsigned types */ -template::result> +template::value> struct Absolute { static T eval(T v) { return v<0 ? -v : v; } }; @@ -119,7 +115,7 @@ T str_to_int(const string &s, const Fmt &f) bool neg = false; if(*i=='-') { - if(!IsSigned::result) + if(is_unsigned::value) throw lexical_error(format("conversion of '%s' to unsigned integer", s)); neg = true; ++i; diff --git a/source/strings/lexicalcast.h b/source/strings/lexicalcast.h index 22b45e8..4f54a85 100644 --- a/source/strings/lexicalcast.h +++ b/source/strings/lexicalcast.h @@ -114,7 +114,7 @@ template struct HasFormattedInput: Sfinae::Evaluate -typename EnableIf::value, void>::Yes +typename std::enable_if::value>::type operator<<(LexicalConverter &c, const T &v) { std::ostringstream ss; @@ -123,7 +123,7 @@ operator<<(LexicalConverter &c, const T &v) } template -typename EnableIf::value, void>::Yes +typename std::enable_if::value>::type operator>>(const LexicalConverter &c, T &v) { std::istringstream ss(c.get());