From e12919329667013f82cd7653ecc7c2ba349dbe0d Mon Sep 17 00:00:00 2001 From: Zach Laine Date: Sun, 3 Mar 2024 16:54:23 -0600 Subject: [PATCH] Now that the library requires C++17, use std::any instead of any_copyable. --- include/boost/parser/parser.hpp | 8 ++-- include/boost/parser/parser_fwd.hpp | 64 +---------------------------- test/parser.cpp | 6 +-- test/parser_api.cpp | 6 +-- 4 files changed, 8 insertions(+), 76 deletions(-) diff --git a/include/boost/parser/parser.hpp b/include/boost/parser/parser.hpp index 3a31b428..b3402822 100644 --- a/include/boost/parser/parser.hpp +++ b/include/boost/parser/parser.hpp @@ -938,16 +938,16 @@ namespace boost { namespace parser { using trie_t = text::trie, T>; symbol_table_tries_t & symbol_table_tries = *context.symbol_table_tries_; - any_copyable & a = symbol_table_tries[(void *)&symbol_parser]; - if (a.empty()) { + std::any & a = symbol_table_tries[(void *)&symbol_parser]; + if (!a.has_value()) { a = trie_t{}; - trie_t & trie = a.cast(); + trie_t & trie = *std::any_cast(&a); for (auto const & e : symbol_parser.initial_elements()) { trie.insert(e.first | text::as_utf32, e.second); } return trie; } else { - return a.cast(); + return *std::any_cast(&a); } } diff --git a/include/boost/parser/parser_fwd.hpp b/include/boost/parser/parser_fwd.hpp index ee0708eb..fcfda326 100644 --- a/include/boost/parser/parser_fwd.hpp +++ b/include/boost/parser/parser_fwd.hpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -70,69 +71,8 @@ namespace boost { namespace parser { in_apply_parser = 1 << 3 }; - struct any_copyable - { - template< - typename T, - typename Enable = std::enable_if_t>> - any_copyable(T && v) : - impl_(new holder>(std::move(v))) - {} - template - any_copyable(T const & v) : impl_(new holder(v)) - {} - - any_copyable() = default; - any_copyable(any_copyable const & other) - { - if (other.impl_) - impl_ = other.impl_->clone(); - } - any_copyable & operator=(any_copyable const & other) - { - any_copyable temp(other); - swap(temp); - return *this; - } - any_copyable(any_copyable &&) = default; - any_copyable & operator=(any_copyable &&) = default; - - bool empty() const { return impl_.get() == nullptr; } - - template - T & cast() const - { - BOOST_PARSER_DEBUG_ASSERT(impl_); - BOOST_PARSER_DEBUG_ASSERT(dynamic_cast *>(impl_.get())); - return static_cast *>(impl_.get())->value_; - } - - void swap(any_copyable & other) { std::swap(impl_, other.impl_); } - - private: - struct holder_base - { - virtual ~holder_base() {} - virtual std::unique_ptr clone() const = 0; - }; - template - struct holder : holder_base - { - holder(T && v) : value_(std::move(v)) {} - holder(T const & v) : value_(v) {} - virtual ~holder() {} - virtual std::unique_ptr clone() const - { - return std::unique_ptr(new holder{value_}); - } - T value_; - }; - - std::unique_ptr impl_; - }; - using symbol_table_tries_t = - std::map>; + std::map>; template< bool DoTrace, diff --git a/test/parser.cpp b/test/parser.cpp index f5c8803d..39b44eb6 100644 --- a/test/parser.cpp +++ b/test/parser.cpp @@ -2044,11 +2044,7 @@ TEST(parser, combined_seq_and_or) { std::string str = "abc"; - tuple< - boost::parser::detail::any_copyable, - boost::parser::detail::any_copyable, - boost::parser::detail::any_copyable> - chars; + tuple chars; EXPECT_TRUE(parse(str, parser, chars)); } diff --git a/test/parser_api.cpp b/test/parser_api.cpp index 0b975087..a9cff820 100644 --- a/test/parser_api.cpp +++ b/test/parser_api.cpp @@ -1816,11 +1816,7 @@ TEST(parser, combined_seq_and_or) { char const * str = "abc"; - tuple< - boost::parser::detail::any_copyable, - boost::parser::detail::any_copyable, - boost::parser::detail::any_copyable> - chars; + tuple chars; EXPECT_TRUE(parse(str, parser, chars)); }