From 0daa97a5f0148a38166a99e6958a1879bcdbf1ea Mon Sep 17 00:00:00 2001 From: Matthew Paletta Date: Mon, 15 Jun 2020 16:52:47 -0700 Subject: [PATCH] Added templated move support for antlrcpp::Any --- contributors.txt | 1 + runtime/Cpp/runtime/src/support/Any.h | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/contributors.txt b/contributors.txt index e24449596..c20f1ab12 100644 --- a/contributors.txt +++ b/contributors.txt @@ -244,3 +244,4 @@ YYYY/MM/DD, github id, Full name, email 2020/04/07, deniskyashif, Denis Kyashif, denis.kyashif@gmail.com 2020/04/30, TristonianJones, Tristan Swadell, tswadell@google.com 2020/05/31, d-markey, David Markey, dmarkey@free.fr +2020/06/15, mattpaletta, Matthew Paletta, mattpaletta@gmail.com diff --git a/runtime/Cpp/runtime/src/support/Any.h b/runtime/Cpp/runtime/src/support/Any.h index 5db59f6e6..938f04362 100644 --- a/runtime/Cpp/runtime/src/support/Any.h +++ b/runtime/Cpp/runtime/src/support/Any.h @@ -65,16 +65,26 @@ struct ANTLR4CPP_PUBLIC Any return derived->value; } - template + template::value || std::is_copy_assignable::value>::value> operator U() { return as>(); } - template + template::value && !std::is_copy_assignable::value) && (std::is_move_constructible::value || std::is_move_assignable::value)>::value> + operator U() { + return std::move(as>()); + } + + template::value || std::is_copy_assignable::value>::value> operator const U() const { return as>(); } + template::value && !std::is_copy_assignable::value) && (std::is_move_constructible::value || std::is_move_assignable::value)>::value> + operator const U() const { + return std::move(as>()); + } + Any& operator = (const Any& a) { if (_ptr == a._ptr) return *this; @@ -99,7 +109,7 @@ struct ANTLR4CPP_PUBLIC Any virtual ~Any(); - virtual bool equals(Any other) const { + virtual bool equals(const Any& other) const { return _ptr == other._ptr; }