Merge pull request #2849 from mattpaletta/master

Added templated move support for antlrcpp::Any
This commit is contained in:
Terence Parr 2021-04-12 08:27:34 -07:00 committed by GitHub
commit e404d26f61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -269,6 +269,7 @@ YYYY/MM/DD, github id, Full name, email
2020/06/02, cohomology, Kilian Kilger, kkilger AT gmail.com
2020/06/04, IohannRabeson, Iohann Rabeson, iotaka6@gmail.com
2020/06/04, sigmasoldi3r, Pablo Blanco, pablobc.1995@gmail.com
2020/06/15, mattpaletta, Matthew Paletta, mattpaletta@gmail.com
2020/07/01, sha-N, Shan M Mathews, admin@bluestarqatar.com
2020/08/22, stevenjohnstone, Steven Johnstone, steven.james.johnstone@gmail.com
2020/09/06, ArthurSonzogni, Sonzogni Arthur, arthursonzogni@gmail.com

View File

@ -65,16 +65,26 @@ struct ANTLR4CPP_PUBLIC Any
return derived->value;
}
template<class U>
template<class U, typename std::enable_if<std::is_copy_constructible<U>::value || std::is_copy_assignable<U>::value>::value>
operator U() {
return as<StorageType<U>>();
}
template<class U>
template<class U, typename std::enable_if<(!std::is_copy_constructible<U>::value && !std::is_copy_assignable<U>::value) && (std::is_move_constructible<U>::value || std::is_move_assignable<U>::value)>::value>
operator U() {
return std::move(as<StorageType<U>>());
}
template<class U, typename std::enable_if<std::is_copy_constructible<U>::value || std::is_copy_assignable<U>::value>::value>
operator const U() const {
return as<const StorageType<U>>();
}
template<class U, typename std::enable_if<!(!std::is_copy_constructible<U>::value && !std::is_copy_assignable<U>::value) && (std::is_move_constructible<U>::value || std::is_move_assignable<U>::value)>::value>
operator const U() const {
return std::move(as<const StorageType<U>>());
}
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;
}