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 | 42 | } |
| 43 | 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 | 52 | struct Combiner { |
| 52 | 53 | int num; |
| ... | ... | @@ -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 | 269 | bool lexical_cast(std::string input, T& output) { |
| 269 | 270 | logit("Int lexical cast " + input); |
| 270 | 271 | try{ |
| ... | ... | @@ -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 | 282 | bool lexical_cast(std::string input, T& output) { |
| 282 | 283 | logit("Floating lexical cast " + input); |
| 283 | 284 | try{ |
| ... | ... | @@ -292,7 +293,7 @@ bool lexical_cast(std::string input, T& output) { |
| 292 | 293 | |
| 293 | 294 | // String and similar |
| 294 | 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 | 297 | bool lexical_cast(std::string input, T& output) { |
| 297 | 298 | logit("Direct lexical cast: " + input); |
| 298 | 299 | output = input; |
| ... | ... | @@ -383,7 +384,7 @@ public: |
| 383 | 384 | } |
| 384 | 385 | |
| 385 | 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 | 388 | void add_option( |
| 388 | 389 | std::string name, ///< The name, long,short |
| 389 | 390 | T &variable, ///< The variable to set |
| ... | ... | @@ -447,7 +448,7 @@ public: |
| 447 | 448 | } |
| 448 | 449 | |
| 449 | 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 | 452 | void add_flag( |
| 452 | 453 | std::string name, ///< The name, short,long |
| 453 | 454 | T &count, ///< A varaible holding the count | ... | ... |