diff --git a/include/CLI.hpp b/include/CLI.hpp index 6a7e8bf4..7bf0278c 100644 --- a/include/CLI.hpp +++ b/include/CLI.hpp @@ -36,6 +36,18 @@ std::string join(const T& v, std::string delim = ",") { namespace CLI { +// Based generally on https://rmf.io/cxx11/almost-static-if +namespace detail { + enum class enabler {}; +} +constexpr detail::enabler dummy = {}; + +template +using EnableIf = typename std::enable_if::type; +template +using DisableIf = typename std::enable_if::type; + + struct Combiner { int num; bool positional; @@ -252,9 +264,8 @@ public: }; -template -typename std::enable_if::value, bool>::type -lexical_cast(std::string input, T& output) { +template> = dummy> +bool lexical_cast(std::string input, T& output) { logit("Int lexical cast " + input); try{ output = (T) std::stoll(input); @@ -266,9 +277,8 @@ lexical_cast(std::string input, T& output) { } } -template -typename std::enable_if::value, bool>::type -lexical_cast(std::string input, T& output) { +template> = dummy> +bool lexical_cast(std::string input, T& output) { logit("Floating lexical cast " + input); try{ output = (T) std::stold(input); @@ -281,11 +291,9 @@ lexical_cast(std::string input, T& output) { } // String and similar -template -typename std::enable_if< - !std::is_floating_point::value - && !std::is_integral::value, bool>::type -lexical_cast(std::string input, T& output) { +template::value && !std::is_integral::value, detail::enabler>::type = dummy> +bool lexical_cast(std::string input, T& output) { logit("Direct lexical cast: " + input); output = input; return true; @@ -375,9 +383,8 @@ public: } /// Add option for string - template - typename std::enable_if::value, void>::type - add_option( + template> = dummy> + void add_option( std::string name, ///< The name, long,short T &variable, ///< The variable to set std::string discription="", ///< Discription string @@ -440,11 +447,10 @@ public: } /// Add option for flag - template - typename std::enable_if::value, void>::type - add_flag( + template> = dummy> + void add_flag( std::string name, ///< The name, short,long - T &count, ///< A varaible holding the count + T &count, ///< A varaible holding the count std::string discription="" ///< Discription string ) {