mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-01 21:23:52 +00:00
Better version of EnableIf
This commit is contained in:
parent
b73d1bd9b2
commit
9376400d74
@ -42,11 +42,12 @@ namespace detail {
|
|||||||
}
|
}
|
||||||
constexpr detail::enabler dummy = {};
|
constexpr detail::enabler dummy = {};
|
||||||
|
|
||||||
template <typename Condition>
|
// Copied from C++14
|
||||||
using EnableIf = typename std::enable_if<Condition::value, detail::enabler>::type;
|
// template< bool B, class T = void >
|
||||||
template <typename Condition>
|
// using enable_if_t = typename std::enable_if<B,T>::type;
|
||||||
using DisableIf = typename std::enable_if<!Condition::value, detail::enabler>::type;
|
|
||||||
|
|
||||||
|
template <bool Condition>
|
||||||
|
using EnableIf = typename std::enable_if<Condition, detail::enabler>::type;
|
||||||
|
|
||||||
struct Combiner {
|
struct Combiner {
|
||||||
int num;
|
int num;
|
||||||
@ -264,7 +265,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename T, EnableIf<std::is_integral<T>> = dummy>
|
template<typename T, EnableIf<std::is_integral<T>::value> = dummy>
|
||||||
bool lexical_cast(std::string input, T& output) {
|
bool lexical_cast(std::string input, T& output) {
|
||||||
logit("Int lexical cast " + input);
|
logit("Int lexical cast " + input);
|
||||||
try{
|
try{
|
||||||
@ -277,7 +278,7 @@ bool lexical_cast(std::string input, T& output) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, EnableIf<std::is_floating_point<T>> = dummy>
|
template<typename T, EnableIf<std::is_floating_point<T>::value> = dummy>
|
||||||
bool lexical_cast(std::string input, T& output) {
|
bool lexical_cast(std::string input, T& output) {
|
||||||
logit("Floating lexical cast " + input);
|
logit("Floating lexical cast " + input);
|
||||||
try{
|
try{
|
||||||
@ -292,7 +293,7 @@ bool lexical_cast(std::string input, T& output) {
|
|||||||
|
|
||||||
// String and similar
|
// String and similar
|
||||||
template<typename T,
|
template<typename T,
|
||||||
typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value, detail::enabler>::type = dummy>
|
EnableIf<!std::is_floating_point<T>::value && !std::is_integral<T>::value> = dummy>
|
||||||
bool lexical_cast(std::string input, T& output) {
|
bool lexical_cast(std::string input, T& output) {
|
||||||
logit("Direct lexical cast: " + input);
|
logit("Direct lexical cast: " + input);
|
||||||
output = input;
|
output = input;
|
||||||
@ -383,7 +384,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Add option for string
|
/// Add option for string
|
||||||
template<typename T, DisableIf<std::is_array<T>> = dummy>
|
template<typename T, EnableIf<!std::is_array<T>::value> = dummy>
|
||||||
void add_option(
|
void add_option(
|
||||||
std::string name, ///< The name, long,short
|
std::string name, ///< The name, long,short
|
||||||
T &variable, ///< The variable to set
|
T &variable, ///< The variable to set
|
||||||
@ -447,7 +448,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Add option for flag
|
/// Add option for flag
|
||||||
template<typename T, EnableIf<std::is_integral<T>> = dummy>
|
template<typename T, EnableIf<std::is_integral<T>::value> = dummy>
|
||||||
void add_flag(
|
void add_flag(
|
||||||
std::string name, ///< The name, short,long
|
std::string name, ///< The name, short,long
|
||||||
T &count, ///< A varaible holding the count
|
T &count, ///< A varaible holding the count
|
||||||
|
Loading…
x
Reference in New Issue
Block a user