Skip to content

Commit

Permalink
FieldValue: Switch to std::variant
Browse files Browse the repository at this point in the history
Since moving to C++17 we can replace boost::variant with std::variant.

Confirmed amqpprox runs OK and the unit tests log a method
containing a FieldTable.
  • Loading branch information
adamncasey committed Jun 30, 2021
1 parent a5e1c00 commit 9dcea20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
7 changes: 4 additions & 3 deletions libamqpprox/amqpprox_fieldvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <amqpprox_fieldtable.h>

#include <iostream>
#include <variant>

namespace Bloomberg {
namespace amqpprox {
Expand Down Expand Up @@ -68,15 +69,15 @@ std::ostream &operator<<(std::ostream &os, const FieldValue &value)
{
switch (value.d_type) {
case 'F':
os << *boost::get<std::shared_ptr<FieldTable>>(value.d_value);
os << *std::get<std::shared_ptr<FieldTable>>(value.d_value);
break;
case 'S':
os << "\"";
boost::apply_visitor(FieldValuePrinter(os), value.d_value);
std::visit(FieldValuePrinter(os), value.d_value);
os << "\"";
break;
default:
boost::apply_visitor(FieldValuePrinter(os), value.d_value);
std::visit(FieldValuePrinter(os), value.d_value);
break;
}
return os;
Expand Down
23 changes: 11 additions & 12 deletions libamqpprox/amqpprox_fieldvalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
#ifndef BLOOMBERG_AMQPPROX_FIELDVALUE
#define BLOOMBERG_AMQPPROX_FIELDVALUE

#include <boost/variant.hpp>

#include <iosfwd>
#include <memory>
#include <variant>
#include <vector>

namespace Bloomberg {
Expand All @@ -32,13 +31,13 @@ class FieldTable;
* https://www.rabbitmq.com/amqp-0-9-1-errata.html
*/
class FieldValue {
boost::variant<std::string,
uint64_t,
int64_t,
bool,
std::vector<uint8_t>,
std::vector<FieldValue>,
std::shared_ptr<FieldTable>>
std::variant<std::string,
uint64_t,
int64_t,
bool,
std::vector<uint8_t>,
std::vector<FieldValue>,
std::shared_ptr<FieldTable>>
d_value;
char d_type;

Expand Down Expand Up @@ -134,13 +133,13 @@ inline char FieldValue::type() const
template <typename T>
T FieldValue::value()
{
return boost::get<T>(d_value);
return std::get<T>(d_value);
}

template <typename T>
T FieldValue::value() const
{
return boost::get<T>(d_value);
return std::get<T>(d_value);
}

std::ostream &operator<<(std::ostream &os, const FieldValue &value);
Expand All @@ -155,7 +154,7 @@ inline bool operator!=(const FieldValue &lhs, const FieldValue &rhs)
return !(lhs == rhs);
}

class FieldValuePrinter : public boost::static_visitor<std::ostream &> {
class FieldValuePrinter {
std::ostream &d_printStream;

public:
Expand Down

0 comments on commit 9dcea20

Please sign in to comment.