From 54297cd329c4e784ae4ce28e0d5598926693571c Mon Sep 17 00:00:00 2001 From: Zongyuan Zuo Date: Mon, 26 Feb 2018 19:51:21 +0800 Subject: [PATCH] rewrite + add patch to all stl containers --- runtime/Cpp/runtime/src/support/Any.h | 34 +++++++++++---------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/runtime/Cpp/runtime/src/support/Any.h b/runtime/Cpp/runtime/src/support/Any.h index aa08ac0cc..ebd359d1d 100644 --- a/runtime/Cpp/runtime/src/support/Any.h +++ b/runtime/Cpp/runtime/src/support/Any.h @@ -41,14 +41,14 @@ struct ANTLR4CPP_PUBLIC Any } template - Any(U&& value) : _ptr(new Derived, Cloneable>::value>(std::forward(value))) { + Any(U&& value) : _ptr(new Derived>(std::forward(value))) { } template bool is() const { typedef StorageType T; - auto derived = dynamic_cast::value> *>(_ptr); + auto derived = dynamic_cast *>(_ptr); return derived != nullptr; } @@ -57,7 +57,7 @@ struct ANTLR4CPP_PUBLIC Any StorageType& as() { typedef StorageType T; - auto derived = dynamic_cast::value>*>(_ptr); + auto derived = dynamic_cast*>(_ptr); if (!derived) throw std::bad_cast(); @@ -99,21 +99,18 @@ struct ANTLR4CPP_PUBLIC Any } private: - template + template struct Cloneable : std::is_copy_constructible {}; - template - struct Cloneable> : std::is_copy_constructible {}; + template class C> + struct Cloneable, typename std::enable_if>::value && !std::is_nothrow_copy_constructible>::value>::type> : std::is_copy_constructible {}; struct Base { virtual ~Base() {}; virtual Base* clone() const = 0; }; - template - struct Derived; - template - struct Derived : Base + struct Derived : Base { template Derived(U&& value_) : value(std::forward(value_)) { } @@ -121,20 +118,17 @@ private: T value; Base* clone() const { - return new Derived::value>(value); + return clone<>(); } - }; - - template - struct Derived : Base - { - template Derived(U&& value_) : value(std::forward(value_)) { + private: + template + auto clone() const -> typename std::enable_if::value, Base*>::type { + return new Derived(value); } - T value; - - Base* clone() const { + template + auto clone() const -> typename std::enable_if::value, Base*>::type { return nullptr; }