common/config: s/boost::variant/std::variant/

we should use standard library for more well defined behavior, and
less dependencies on 3rd party libraries.

Signed-off-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2021-06-27 11:48:24 +08:00
parent 863d8385d0
commit 32e62f9a64
2 changed files with 21 additions and 24 deletions

View File

@ -13,8 +13,6 @@
*/
#include <filesystem>
#include <boost/type_traits.hpp>
#include "common/ceph_argparse.h"
#include "common/common_init.h"
#include "common/config.h"
@ -1455,7 +1453,7 @@ int md_config_t::_rm_val(ConfigValues& values,
namespace {
template<typename Size>
struct get_size_visitor : public boost::static_visitor<Size>
struct get_size_visitor
{
get_size_visitor() {}
@ -1474,34 +1472,33 @@ struct get_size_visitor : public boost::static_visitor<Size>
/**
* Handles assigning from a variant-of-types to a variant-of-pointers-to-types
*/
template<class Config>
class assign_visitor : public boost::static_visitor<>
class assign_visitor
{
Config *conf;
ConfigValues *conf;
Option::value_t val;
public:
assign_visitor(Config *conf_, Option::value_t val_)
assign_visitor(ConfigValues *conf_, Option::value_t val_)
: conf(conf_), val(val_)
{}
template <typename T>
void operator()(T Config::* ptr) const
void operator()(T ConfigValues::* ptr) const
{
T *member = const_cast<T *>(&(conf->*(boost::get<const T Config::*>(ptr))));
T *member = const_cast<T *>(&(conf->*(ptr)));
*member = std::get<T>(val);
}
void operator()(uint64_t Config::* ptr) const
void operator()(uint64_t ConfigValues::* ptr) const
{
using T = uint64_t;
auto member = const_cast<T*>(&(conf->*(boost::get<const T Config::*>(ptr))));
auto member = const_cast<T*>(&(conf->*(ptr)));
*member = std::visit(get_size_visitor<T>{}, val);
}
void operator()(int64_t Config::* ptr) const
void operator()(int64_t ConfigValues::* ptr) const
{
using T = int64_t;
auto member = const_cast<T*>(&(conf->*(boost::get<const T Config::*>(ptr))));
auto member = const_cast<T*>(&(conf->*(ptr)));
*member = std::visit(get_size_visitor<T>{}, val);
}
};
@ -1522,7 +1519,7 @@ void md_config_t::update_legacy_val(ConfigValues& values,
md_config_t::member_ptr_t member_ptr)
{
Option::value_t v = _get_val(values, opt);
boost::apply_visitor(assign_visitor(&values, v), member_ptr);
std::visit(assign_visitor(&values, v), member_ptr);
}
static void dump(Formatter *f, int level, Option::value_t in)

View File

@ -16,8 +16,8 @@
#define CEPH_CONFIG_H
#include <map>
#include <variant>
#include <boost/container/small_vector.hpp>
#include <boost/variant.hpp>
#include "common/ConfUtils.h"
#include "common/code_environment.h"
#include "log/SubsystemMap.h"
@ -70,14 +70,14 @@ extern const char *ceph_conf_level_name(int level);
*/
struct md_config_t {
public:
typedef boost::variant<int64_t ConfigValues::*,
uint64_t ConfigValues::*,
std::string ConfigValues::*,
double ConfigValues::*,
bool ConfigValues::*,
entity_addr_t ConfigValues::*,
entity_addrvec_t ConfigValues::*,
uuid_d ConfigValues::*> member_ptr_t;
typedef std::variant<int64_t ConfigValues::*,
uint64_t ConfigValues::*,
std::string ConfigValues::*,
double ConfigValues::*,
bool ConfigValues::*,
entity_addr_t ConfigValues::*,
entity_addrvec_t ConfigValues::*,
uuid_d ConfigValues::*> member_ptr_t;
// For use when intercepting configuration updates
typedef std::function<bool(
@ -361,7 +361,7 @@ const T md_config_t::get_val(const ConfigValues& values,
return std::get<T>(this->get_val_generic(values, key));
}
inline std::ostream& operator<<(std::ostream& o, const boost::blank& ) {
inline std::ostream& operator<<(std::ostream& o, const std::monostate&) {
return o << "INVALID_CONFIG_VALUE";
}