From: Kefu Chai Date: Wed, 7 Jun 2017 03:11:55 +0000 (+0800) Subject: common/options: specialize on non bool integeral types X-Git-Tag: v12.1.2~192^2~40 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2c6669c5a4c1650138eb7aa7c0250220d40d08cd;p=ceph.git common/options: specialize on non bool integeral types Signed-off-by: Kefu Chai --- diff --git a/src/common/options.h b/src/common/options.h index 570ce531cd64..e0e097b11b85 100644 --- a/src/common/options.h +++ b/src/common/options.h @@ -38,13 +38,13 @@ struct Option { LEVEL_DEV, } level_t; - typedef boost::variant< + using value_t = boost::variant< std::string, int64_t, double, bool//, //entity_addr_t, - /*uuid_d*/> value_t; + /*uuid_d*/>; std::string name; type_t type; level_t level; @@ -66,20 +66,34 @@ struct Option { : name(name), type(t), level(l) {} + // bool is an integer, but we don't think so. teach it the hard way. template - Option& set_default(const T& v) { - value = v; + using is_not_integer = std::enable_if::value || + std::is_same::value, int>; + template + using is_integer = std::enable_if::value && + !std::is_same::value, int>; + template::type = 0> + Option& set_value(value_t& v, const T& new_value) { + v = new_value; + return *this; + } + template::type = 0> + Option& set_value(value_t& v, T new_value) { + v = int64_t(new_value); return *this; } template + Option& set_default(const T& v) { + return set_value(value, v); + } + template Option& set_daemon_default(const T& v) { - daemon_value = v; - return *this; + return set_value(daemon_value, v); } template Option& set_nondaemon_default(const T& v) { - daemon_value = v; - return *this; + return set_value(nondaemon_value, v); } Option& add_tag(const char* t) { tags.push_back(t);