From 0fd1e7834996c435883ec0bcf8237e79415a6426 Mon Sep 17 00:00:00 2001 From: Mikhail Koviazin Date: Fri, 6 Dec 2024 14:52:56 +0100 Subject: [PATCH] AVRO-4097: Replace boost::any with std::any; boost::tuple with std::tuple (#3256) * AVRO-4097: [C++] replace boost::any with std::any Signed-off-by: Mikhail Koviazin * AVRO-4097: [C++] replace boost::tuple with std::tuple Signed-off-by: Mikhail Koviazin --------- Signed-off-by: Mikhail Koviazin --- lang/c++/impl/json/JsonDom.cc | 4 +-- lang/c++/impl/json/JsonDom.hh | 14 ++++----- lang/c++/impl/parsing/Symbol.hh | 55 ++++++++++++++++----------------- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/lang/c++/impl/json/JsonDom.cc b/lang/c++/impl/json/JsonDom.cc index c2696d827ad..b36abad11de 100644 --- a/lang/c++/impl/json/JsonDom.cc +++ b/lang/c++/impl/json/JsonDom.cc @@ -145,12 +145,12 @@ void Entity::ensureType(EntityType type) const { String Entity::stringValue() const { ensureType(EntityType::String); - return JsonParser::toStringValue(**boost::any_cast>(&value_)); + return JsonParser::toStringValue(**std::any_cast>(&value_)); } String Entity::bytesValue() const { ensureType(EntityType::String); - return JsonParser::toBytesValue(**boost::any_cast>(&value_)); + return JsonParser::toBytesValue(**std::any_cast>(&value_)); } std::string Entity::toString() const { diff --git a/lang/c++/impl/json/JsonDom.hh b/lang/c++/impl/json/JsonDom.hh index 2a0695adff6..8aa1809729d 100644 --- a/lang/c++/impl/json/JsonDom.hh +++ b/lang/c++/impl/json/JsonDom.hh @@ -19,6 +19,7 @@ #ifndef avro_json_JsonDom_hh__ #define avro_json_JsonDom_hh__ +#include #include #include #include @@ -27,7 +28,6 @@ #include #include "Config.hh" -#include "boost/any.hpp" namespace avro { @@ -67,7 +67,7 @@ inline std::ostream &operator<<(std::ostream &os, EntityType et) { class AVRO_DECL Entity { EntityType type_; - boost::any value_; + std::any value_; size_t line_; // can't be const else noncopyable... void ensureType(EntityType) const; @@ -99,17 +99,17 @@ public: Bool boolValue() const { ensureType(EntityType::Bool); - return boost::any_cast(value_); + return std::any_cast(value_); } Long longValue() const { ensureType(EntityType::Long); - return boost::any_cast(value_); + return std::any_cast(value_); } Double doubleValue() const { ensureType(EntityType::Double); - return boost::any_cast(value_); + return std::any_cast(value_); } String stringValue() const; @@ -118,12 +118,12 @@ public: const Array &arrayValue() const { ensureType(EntityType::Arr); - return **boost::any_cast>(&value_); + return **std::any_cast>(&value_); } const Object &objectValue() const { ensureType(EntityType::Obj); - return **boost::any_cast>(&value_); + return **std::any_cast>(&value_); } std::string toString() const; diff --git a/lang/c++/impl/parsing/Symbol.hh b/lang/c++/impl/parsing/Symbol.hh index bbba58e6a0e..08b97240050 100644 --- a/lang/c++/impl/parsing/Symbol.hh +++ b/lang/c++/impl/parsing/Symbol.hh @@ -20,16 +20,15 @@ #define avro_parsing_Symbol_hh__ #include +#include #include #include #include #include +#include #include #include -#include -#include - #include "Decoder.hh" #include "Exception.hh" #include "Node.hh" @@ -39,10 +38,10 @@ namespace parsing { class Symbol; -typedef std::vector Production; -typedef std::shared_ptr ProductionPtr; -typedef boost::tuple, bool, ProductionPtr, ProductionPtr> RepeaterInfo; -typedef boost::tuple RootInfo; +using Production = std::vector; +using ProductionPtr = std::shared_ptr; +using RepeaterInfo = std::tuple, bool, ProductionPtr, ProductionPtr>; +using RootInfo = std::tuple; class Symbol { public: @@ -92,7 +91,7 @@ public: private: Kind kind_; - boost::any extra_; + std::any extra_; explicit Symbol(Kind k) : kind_(k) {} template @@ -105,17 +104,17 @@ public: template T extra() const { - return boost::any_cast(extra_); + return std::any_cast(extra_); } template T *extrap() { - return boost::any_cast(&extra_); + return std::any_cast(&extra_); } template const T *extrap() const { - return boost::any_cast(&extra_); + return std::any_cast(&extra_); } template @@ -340,8 +339,8 @@ void fixup(Symbol &s, const std::map &m, } break; case Symbol::Kind::Repeater: { const RepeaterInfo &ri = *s.extrap(); - fixup_internal(boost::tuples::get<2>(ri), m, seen); - fixup_internal(boost::tuples::get<3>(ri), m, seen); + fixup_internal(std::get<2>(ri), m, seen); + fixup_internal(std::get<3>(ri), m, seen); } break; case Symbol::Kind::Placeholder: { typename std::map>::const_iterator it = @@ -419,7 +418,7 @@ public: } else { switch (s.kind()) { case Symbol::Kind::Root: - append(boost::tuples::get<0>(*s.extrap())); + append(std::get<0>(*s.extrap())); continue; case Symbol::Kind::Indirect: { ProductionPtr pp = @@ -437,7 +436,7 @@ public: continue; case Symbol::Kind::Repeater: { auto *p = s.extrap(); - std::stack &ns = boost::tuples::get<0>(*p); + std::stack &ns = std::get<0>(*p); if (ns.empty()) { throw Exception( "Empty item count stack in repeater advance"); @@ -447,7 +446,7 @@ public: "Zero item count in repeater advance"); } --ns.top(); - append(boost::tuples::get<2>(*p)); + append(std::get<2>(*p)); } continue; case Symbol::Kind::Error: @@ -527,7 +526,7 @@ public: } Symbol &t2 = parsingStack.top(); auto *p = t2.extrap(); - boost::tuples::get<0>(*p).push(n); + std::get<0>(*p).push(n); continue; } case Symbol::Kind::ArrayEnd: @@ -542,7 +541,7 @@ public: } Symbol &t2 = parsingStack.top(); auto *p2 = t2.extrap(); - boost::tuples::get<0>(*p2).push(n); + std::get<0>(*p2).push(n); continue; } case Symbol::Kind::MapEnd: @@ -564,19 +563,19 @@ public: } case Symbol::Kind::Repeater: { auto *p = t.extrap(); - std::stack &ns = boost::tuples::get<0>(*p); + std::stack &ns = std::get<0>(*p); if (ns.empty()) { throw Exception( "Empty item count stack in repeater skip"); } ssize_t &n = ns.top(); if (n == 0) { - n = boost::tuples::get<1>(*p) ? d.arrayNext() - : d.mapNext(); + n = std::get<1>(*p) ? d.arrayNext() + : d.mapNext(); } if (n != 0) { --n; - append(boost::tuples::get<3>(*p)); + append(std::get<3>(*p)); continue; } else { ns.pop(); @@ -680,7 +679,7 @@ public: Symbol &s = parsingStack.top(); assertMatch(Symbol::Kind::Repeater, s.kind()); auto *p = s.extrap(); - std::stack &nn = boost::tuples::get<0>(*p); + std::stack &nn = std::get<0>(*p); nn.push(n); } @@ -689,7 +688,7 @@ public: Symbol &s = parsingStack.top(); assertMatch(Symbol::Kind::Repeater, s.kind()); auto *p = s.extrap(); - std::stack &nn = boost::tuples::get<0>(*p); + std::stack &nn = std::get<0>(*p); if (nn.empty() || nn.top() != 0) { throw Exception("Wrong number of items"); } @@ -701,7 +700,7 @@ public: Symbol &s = parsingStack.top(); assertMatch(Symbol::Kind::Repeater, s.kind()); auto *p = s.extrap(); - std::stack &ns = boost::tuples::get<0>(*p); + std::stack &ns = std::get<0>(*p); if (ns.empty()) { throw Exception("Incorrect number of items (empty)"); } @@ -770,7 +769,7 @@ public: parsingStack.pop(); } Symbol &s = parsingStack.top(); - append(boost::tuples::get<0>(*s.extrap())); + append(std::get<0>(*s.extrap())); } }; @@ -790,8 +789,8 @@ inline std::ostream &operator<<(std::ostream &os, const Symbol &s) { case Symbol::Kind::Repeater: { const RepeaterInfo &ri = *s.extrap(); os << '(' << Symbol::toString(s.kind()) - << ' ' << *boost::tuples::get<2>(ri) - << ' ' << *boost::tuples::get<3>(ri) + << ' ' << *std::get<2>(ri) + << ' ' << *std::get<3>(ri) << ')'; } break; case Symbol::Kind::Indirect: {