From: Arnaud Giersch Date: Wed, 16 Dec 2020 16:29:01 +0000 (+0100) Subject: bind_flag() with valid_values only works with std:string anyway. X-Git-Tag: v3.27~608 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/081a38309c637c51f527b507704b65d6ce1ac805 bind_flag() with valid_values only works with std:string anyway. Don't hide is behind template parameter. --- diff --git a/include/xbt/config.hpp b/include/xbt/config.hpp index 7d5572cfe2..eeca2250f0 100644 --- a/include/xbt/config.hpp +++ b/include/xbt/config.hpp @@ -149,32 +149,34 @@ bind_flag(T& value, const char* name, std::initializer_list aliases alias(name, aliases); } -template -typename std::enable_if()(std::declval()))>::value, void>::type -bind_flag(T& value, const char* name, const char* description, const std::map& valid_values, F callback) +template +typename std::enable_if()(std::declval()))>::value, + void>::type +bind_flag(std::string& value, const char* name, const char* description, + const std::map& valid_values, F callback) { declare_flag(name, description, value, - std::function([&value, name, valid_values, callback](const T& val) { + std::function([&value, name, valid_values, callback](const std::string& val) { callback(val); if (valid_values.find(val) != valid_values.end()) { value = std::move(val); return; } std::string mesg = "\n"; - if (std::string(val) == "help") + if (val == "help") mesg += std::string("Possible values for option ") + name + ":\n"; else mesg += std::string("Invalid value '") + val + "' for option " + name + ". Possible values:\n"; for (auto const& kv : valid_values) - mesg += " - '" + std::string(kv.first) + "': " + kv.second + - (kv.first == value ? " <=== DEFAULT" : "") + "\n"; + mesg += " - '" + kv.first + "': " + kv.second + (kv.first == value ? " <=== DEFAULT" : "") + "\n"; xbt_die("%s", mesg.c_str()); })); } -template -typename std::enable_if()(std::declval()))>::value, void>::type -bind_flag(T& value, const char* name, std::initializer_list aliases, const char* description, - const std::map& valid_values, F callback) +template +typename std::enable_if()(std::declval()))>::value, + void>::type +bind_flag(std::string& value, const char* name, std::initializer_list aliases, const char* description, + const std::map& valid_values, F callback) { bind_flag(value, name, description, valid_values, std::move(callback)); alias(name, aliases); @@ -250,7 +252,7 @@ public: * and producing an informative error message when an invalid value is passed, or when help is passed as a value. */ template - Flag(const char* name, const char* desc, T value, const std::map& valid_values, F callback) + Flag(const char* name, const char* desc, T value, const std::map& valid_values, F callback) : value_(value), name_(name) { simgrid::config::bind_flag(value_, name, desc, std::move(valid_values), std::move(callback)); @@ -259,7 +261,7 @@ public: /* A constructor with everything */ template Flag(const char* name, std::initializer_list aliases, const char* desc, T value, - const std::map& valid_values, F callback) + const std::map& valid_values, F callback) : value_(value), name_(name) { simgrid::config::bind_flag(value_, name, aliases, desc, valid_values, std::move(callback));