Commit 9376400d74b160ae9ef5881b5640ba372a3077ba
1 parent
b73d1bd9
Better version of EnableIf
Showing
1 changed file
with
10 additions
and
9 deletions
include/CLI.hpp
| @@ -42,11 +42,12 @@ namespace detail { | @@ -42,11 +42,12 @@ namespace detail { | ||
| 42 | } | 42 | } |
| 43 | constexpr detail::enabler dummy = {}; | 43 | constexpr detail::enabler dummy = {}; |
| 44 | 44 | ||
| 45 | -template <typename Condition> | ||
| 46 | -using EnableIf = typename std::enable_if<Condition::value, detail::enabler>::type; | ||
| 47 | -template <typename Condition> | ||
| 48 | -using DisableIf = typename std::enable_if<!Condition::value, detail::enabler>::type; | 45 | +// Copied from C++14 |
| 46 | +// template< bool B, class T = void > | ||
| 47 | +// using enable_if_t = typename std::enable_if<B,T>::type; | ||
| 49 | 48 | ||
| 49 | +template <bool Condition> | ||
| 50 | +using EnableIf = typename std::enable_if<Condition, detail::enabler>::type; | ||
| 50 | 51 | ||
| 51 | struct Combiner { | 52 | struct Combiner { |
| 52 | int num; | 53 | int num; |
| @@ -264,7 +265,7 @@ public: | @@ -264,7 +265,7 @@ public: | ||
| 264 | }; | 265 | }; |
| 265 | 266 | ||
| 266 | 267 | ||
| 267 | -template<typename T, EnableIf<std::is_integral<T>> = dummy> | 268 | +template<typename T, EnableIf<std::is_integral<T>::value> = dummy> |
| 268 | bool lexical_cast(std::string input, T& output) { | 269 | bool lexical_cast(std::string input, T& output) { |
| 269 | logit("Int lexical cast " + input); | 270 | logit("Int lexical cast " + input); |
| 270 | try{ | 271 | try{ |
| @@ -277,7 +278,7 @@ bool lexical_cast(std::string input, T& output) { | @@ -277,7 +278,7 @@ bool lexical_cast(std::string input, T& output) { | ||
| 277 | } | 278 | } |
| 278 | } | 279 | } |
| 279 | 280 | ||
| 280 | -template<typename T, EnableIf<std::is_floating_point<T>> = dummy> | 281 | +template<typename T, EnableIf<std::is_floating_point<T>::value> = dummy> |
| 281 | bool lexical_cast(std::string input, T& output) { | 282 | bool lexical_cast(std::string input, T& output) { |
| 282 | logit("Floating lexical cast " + input); | 283 | logit("Floating lexical cast " + input); |
| 283 | try{ | 284 | try{ |
| @@ -292,7 +293,7 @@ bool lexical_cast(std::string input, T& output) { | @@ -292,7 +293,7 @@ bool lexical_cast(std::string input, T& output) { | ||
| 292 | 293 | ||
| 293 | // String and similar | 294 | // String and similar |
| 294 | template<typename T, | 295 | template<typename T, |
| 295 | -typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value, detail::enabler>::type = dummy> | 296 | +EnableIf<!std::is_floating_point<T>::value && !std::is_integral<T>::value> = dummy> |
| 296 | bool lexical_cast(std::string input, T& output) { | 297 | bool lexical_cast(std::string input, T& output) { |
| 297 | logit("Direct lexical cast: " + input); | 298 | logit("Direct lexical cast: " + input); |
| 298 | output = input; | 299 | output = input; |
| @@ -383,7 +384,7 @@ public: | @@ -383,7 +384,7 @@ public: | ||
| 383 | } | 384 | } |
| 384 | 385 | ||
| 385 | /// Add option for string | 386 | /// Add option for string |
| 386 | - template<typename T, DisableIf<std::is_array<T>> = dummy> | 387 | + template<typename T, EnableIf<!std::is_array<T>::value> = dummy> |
| 387 | void add_option( | 388 | void add_option( |
| 388 | std::string name, ///< The name, long,short | 389 | std::string name, ///< The name, long,short |
| 389 | T &variable, ///< The variable to set | 390 | T &variable, ///< The variable to set |
| @@ -447,7 +448,7 @@ public: | @@ -447,7 +448,7 @@ public: | ||
| 447 | } | 448 | } |
| 448 | 449 | ||
| 449 | /// Add option for flag | 450 | /// Add option for flag |
| 450 | - template<typename T, EnableIf<std::is_integral<T>> = dummy> | 451 | + template<typename T, EnableIf<std::is_integral<T>::value> = dummy> |
| 451 | void add_flag( | 452 | void add_flag( |
| 452 | std::string name, ///< The name, short,long | 453 | std::string name, ///< The name, short,long |
| 453 | T &count, ///< A varaible holding the count | 454 | T &count, ///< A varaible holding the count |