47template <
bool B,
class T =
void>
using enable_if_t =
typename std::enable_if<B, T>::type;
58template <
bool B,
class T,
class F>
using conditional_t =
typename std::conditional<B, T, F>::type;
61template <
typename T>
struct is_bool : std::false_type {};
64template <>
struct is_bool<bool> : std::true_type {};
70template <
typename T>
struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
73template <
typename T>
struct is_shared_ptr<const std::shared_ptr<T>> : std::true_type {};
97 template <
typename TT,
typename SS>
98 static auto test(
int) ->
decltype(lexical_cast(std::declval<const SS &>(), std::declval<TT &>()), std::true_type());
100 template <
typename,
typename>
static auto test(...) -> std::false_type;
120 using type =
typename std::pointer_traits<T>::element_type;
130template <
typename T,
typename _ =
void>
struct pair_adaptor : std::false_type {
132 using first_type =
typename std::remove_const<value_type>::type;
153 using first_type =
typename std::remove_const<typename value_type::first_type>::type;
154 using second_type =
typename std::remove_const<typename value_type::second_type>::type;
158 return std::get<0>(std::forward<Q>(
pair_value));
162 return std::get<1>(std::forward<Q>(
pair_value));
173#pragma GCC diagnostic push
174#pragma GCC diagnostic ignored "-Wnarrowing"
178 template <
typename TT,
typename CC>
179 static auto test(
int, std::true_type) ->
decltype(
182#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
183#pragma nv_diag_suppress 2361
185#pragma diag_suppress 2361
188 TT{std::declval<CC>()}
190#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
191#pragma nv_diag_default 2361
193#pragma diag_default 2361
197 std::is_move_assignable<TT>());
199 template <
typename TT,
typename CC>
static auto test(
int, std::false_type) -> std::false_type;
201 template <
typename,
typename>
static auto test(...) -> std::false_type;
207#pragma GCC diagnostic pop
214 template <
typename TT,
typename SS>
215 static auto test(
int) ->
decltype(std::declval<SS &>() << std::declval<TT>(), std::true_type());
217 template <
typename,
typename>
static auto test(...) -> std::false_type;
225 template <
typename TT,
typename SS>
226 static auto test(
int) ->
decltype(std::declval<SS &>() >> std::declval<TT &>(), std::true_type());
228 template <
typename,
typename>
static auto test(...) -> std::false_type;
236 template <
typename TT>
237 static auto test(
int) ->
decltype(std::declval<TT>().real(), std::declval<TT>().imag(), std::true_type());
239 template <
typename>
static auto test(...) -> std::false_type;
248 std::istringstream
is;
251 return !
is.fail() && !
is.rdbuf()->in_avail();
271 decltype(std::declval<T>().clear()),
272 decltype(std::declval<T>().insert(std::declval<decltype(std::declval<T>().end())>(),
273 std::declval<const typename T::value_type &>()))>,
275 std::is_constructible<T, std::wstring>::value,
289 :
public std::true_type {};
292template <
typename T,
typename _ =
void>
struct is_wrapper : std::false_type {};
300 template <
typename SS>
303 static auto test(
int) ->
decltype(std::tuple_size<typename std::decay<SS>::type>
::value, std::true_type{});
304 template <
typename>
static auto test(...) -> std::false_type;
312auto to_string(T &&value) ->
decltype(std::forward<T>(value)) {
313 return std::forward<T>(value);
321 return std::string(value);
347 is_readable_container<T>::value,
364template <
typename T1,
369 return to_string(std::forward<T>(value));
373template <
typename T1,
378 return std::string{};
383 return std::to_string(value);
388 return std::to_string(
static_cast<typename std::underlying_type<T>::type
>(value));
398template <
typename T,
typename def,
typename Enable =
void>
struct wrapped_type {
404 using type =
typename T::value_type;
415 typename std::
enable_if<!is_tuple_like<T>::value && !is_mutable_container<T>::value &&
416 !std::is_void<T>::value>::type> {
423 static constexpr int value{std::tuple_size<T>::value};
440template <
typename T,
typename Enable =
void>
struct type_count {
447 typename std::
enable_if<!is_wrapper<T>::value && !is_tuple_like<T>::value && !is_complex<T>::value &&
448 !std::is_void<T>::value>::type> {
465 typename std::
enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value &&
466 !is_mutable_container<T>::value>::type> {
471template <
typename T, std::
size_t I>
472constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type
tuple_type_size() {
477template <
typename T, std::
size_t I>
478 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type
tuple_type_size() {
483template <
typename T>
struct type_count<T,
typename std::
enable_if<is_tuple_like<T>::value>::type> {
488template <
typename T>
struct subtype_count {
493template <
typename T,
typename Enable =
void>
struct type_count_min {
494 static const int value{0};
501 typename std::
enable_if<!is_mutable_container<T>::value && !is_tuple_like<T>::value && !is_wrapper<T>::value &&
502 !is_complex<T>::value && !std::is_void<T>::value>::type> {
508 static constexpr int value{1};
515 typename std::
enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value>::type> {
516 static constexpr int value{subtype_count_min<typename T::value_type>::value};
520template <
typename T, std::
size_t I>
521constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type
tuple_type_size_min() {
526template <
typename T, std::
size_t I>
527 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type
tuple_type_size_min() {
537template <
typename T>
struct subtype_count_min {
538 static constexpr int value{is_mutable_container<T>::value
544template <
typename T,
typename Enable =
void>
struct expected_count {
545 static const int value{0};
551 typename std::
enable_if<!is_mutable_container<T>::value && !is_wrapper<T>::value &&
552 !std::is_void<T>::value>::type> {
553 static constexpr int value{1};
563 static constexpr int value{expected_count<typename T::value_type>::value};
595 static constexpr object_category value{object_category::other};
602 typename std::
enable_if<std::is_integral<T>::value && !std::is_same<T, char>::value && std::is_signed<T>::value &&
603 !is_bool<T>::value && !std::is_enum<T>::value>::type> {
604 static constexpr object_category value{object_category::integral_value};
610 typename std::
enable_if<std::is_integral<T>::value && std::is_unsigned<T>::value &&
611 !std::is_same<T, char>::value && !is_bool<T>::value>::type> {
612 static constexpr object_category value{object_category::unsigned_integral};
618 static constexpr object_category value{object_category::char_value};
623 static constexpr object_category value{object_category::boolean_value};
628 static constexpr object_category value{object_category::floating_point};
633#define WIDE_STRING_CHECK \
634 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value
635#define STRING_CHECK true
637#define WIDE_STRING_CHECK true
638#define STRING_CHECK !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value
645 typename std::
enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value && WIDE_STRING_CHECK &&
646 std::is_assignable<T &, std::string>::value>::type> {
647 static constexpr object_category value{object_category::string_assignable};
654 typename std::
enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
655 !std::is_assignable<T &, std::string>::value && (type_count<T>::value == 1) &&
656 WIDE_STRING_CHECK && std::is_constructible<T, std::string>::value>::type> {
657 static constexpr object_category value{object_category::string_constructible};
663 typename std::
enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
664 STRING_CHECK && std::is_assignable<T &, std::wstring>::value>::type> {
665 static constexpr object_category value{object_category::wstring_assignable};
671 typename std::
enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
672 !std::is_assignable<T &, std::wstring>::value && (type_count<T>::value == 1) &&
673 STRING_CHECK && std::is_constructible<T, std::wstring>::value>::type> {
674 static constexpr object_category value{object_category::wstring_constructible};
679 static constexpr object_category value{object_category::enumeration};
683 static constexpr object_category value{object_category::complex_number};
689 using type =
typename std::conditional<
690 !std::is_floating_point<T>::value && !std::is_integral<T>::value &&
691 !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value &&
692 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value &&
693 !is_complex<T>::value && !is_mutable_container<T>::value && !std::is_enum<T>::value,
695 std::false_type>::type;
696 static constexpr bool value = type::value;
702 typename std::
enable_if<(!is_mutable_container<T>::value && is_wrapper<T>::value &&
703 !is_tuple_like<T>::value && uncommon_type<T>::value)>::type> {
704 static constexpr object_category value{object_category::wrapper_value};
711 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
712 is_direct_constructible<T, int>::value>::type> {
713 static constexpr object_category value{object_category::number_constructible};
720 !is_wrapper<T>::value && !is_direct_constructible<T, double>::value &&
721 is_direct_constructible<T, int>::value>::type> {
722 static constexpr object_category value{object_category::integer_constructible};
729 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
730 !is_direct_constructible<T, int>::value>::type> {
731 static constexpr object_category value{object_category::double_constructible};
739 ((type_count<T>::value >= 2 && !is_wrapper<T>::value) ||
740 (uncommon_type<T>::value && !is_direct_constructible<T, double>::value &&
741 !is_direct_constructible<T, int>::value) ||
742 (uncommon_type<T>::value && type_count<T>::value >= 2))>::type> {
743 static constexpr object_category value{object_category::tuple_value};
753 static constexpr object_category value{object_category::container_value};
764constexpr const char *type_name() {
770 classify_object<T>::value == object_category::integer_constructible,
772constexpr const char *type_name() {
778constexpr const char *type_name() {
784 classify_object<T>::value == object_category::number_constructible ||
785 classify_object<T>::value == object_category::double_constructible,
787constexpr const char *type_name() {
794constexpr const char *type_name() {
801constexpr const char *type_name() {
808constexpr const char *type_name() {
815 classify_object<T>::value <= object_category::other,
817constexpr const char *type_name() {
824std::string type_name();
829 classify_object<T>::value == object_category::wrapper_value,
831std::string type_name();
837inline std::string type_name() {
842template <
typename T, std::
size_t I>
843inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type
tuple_name() {
844 return std::string{};
848template <
typename T, std::
size_t I>
852 if(
str.back() ==
',')
861inline std::string type_name() {
863 tname.push_back(
']');
870 classify_object<T>::value == object_category::wrapper_value,
872inline std::string type_name() {
901 if(
input.find_first_of(
"_'") != std::string::npos) {
907 if(
input.compare(0, 2,
"0o") == 0) {
917 if(
input.compare(0, 2,
"0b") == 0) {
946 if(
input ==
"true") {
948 output =
static_cast<T
>(1);
952 if(
input.find_first_of(
"_'") != std::string::npos) {
958 if(
input.compare(0, 2,
"0o") == 0) {
968 if(
input.compare(0, 2,
"0b") == 0) {
992 std::int64_t
ret = 0;
993 if(
val.size() == 1) {
994 if(
val[0] >=
'1' &&
val[0] <=
'9') {
995 return (
static_cast<std::int64_t
>(
val[0]) -
'0');
1030template <
typename T,
1032 classify_object<T>::value == object_category::unsigned_integral,
1039template <
typename T,
1042 if(
input.size() == 1) {
1050template <
typename T,
1066template <
typename T,
1072 char *
val =
nullptr;
1079 if(
input.find_first_of(
"_'") != std::string::npos) {
1089template <
typename T,
1096 auto nloc =
str1.find_last_of(
"+-");
1097 if(
nloc != std::string::npos &&
nloc > 0) {
1100 if(
str1.back() ==
'i' ||
str1.back() ==
'j')
1104 if(
str1.back() ==
'i' ||
str1.back() ==
'j') {
1121template <
typename T,
1155template <
typename T,
1158 typename std::underlying_type<T>::type
val;
1167template <
typename T,
1169 std::is_assignable<T &, typename T::value_type>::value,
1172 typename T::value_type
val;
1180template <
typename T,
1182 !std::is_assignable<T &, typename T::value_type>::value && std::is_assignable<T &, T>::value,
1185 typename T::value_type
val;
1240template <
typename T,
1247#pragma warning(push)
1248#pragma warning(disable : 4800)
1266template <
typename T,
1276template <
typename T,
1281 static_assert(!std::is_same<T, T>::value,
1282 "option object type must have a lexical cast overload or streaming input operator(>>) defined, if it "
1283 "is convertible from another type use the add_option<T, XC>(...) with XC being the known type");
1292 (classify_object<AssignTo>::value == object_category::string_assignable ||
1293 classify_object<AssignTo>::value == object_category::string_constructible ||
1294 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1295 classify_object<AssignTo>::value == object_category::wstring_constructible),
1305 classify_object<AssignTo>::value != object_category::string_assignable &&
1306 classify_object<AssignTo>::value != object_category::string_constructible &&
1307 classify_object<AssignTo>::value != object_category::wstring_assignable &&
1308 classify_object<AssignTo>::value != object_category::wstring_constructible,
1323 classify_object<AssignTo>::value == object_category::wrapper_value,
1327 typename AssignTo::value_type
emptyVal{};
1339 classify_object<AssignTo>::value != object_category::wrapper_value &&
1340 std::is_assignable<AssignTo &, int>::value,
1349#if defined(__clang__)
1351#pragma clang diagnostic push
1352#pragma clang diagnostic ignored "-Wsign-conversion"
1355#if defined(__clang__)
1356#pragma clang diagnostic pop
1382 std::is_move_assignable<AssignTo>::value,
1397 classify_object<AssignTo>::value <= object_category::wrapper_value,
1412 using FirstType =
typename std::remove_const<typename std::tuple_element<0, ConvertTo>::type>::type;
1413 using SecondType =
typename std::tuple_element<1, ConvertTo>::type;
1443 typename AssignTo::value_type
out;
1453 return (!
output.empty());
1464 if(
str1.back() ==
'i' ||
str1.back() ==
'j') {
1528 classify_object<ConvertTo>::value != object_category::wrapper_value &&
1544template <
class AssignTo,
class ConvertTo, std::
size_t I>
1551template <
class AssignTo,
class ConvertTo>
1560template <
class AssignTo,
class ConvertTo>
1571template <
class AssignTo,
class ConvertTo>
1572inline typename std::enable_if<is_mutable_container<ConvertTo>::value ||
1577 std::size_t index{subtype_count_min<ConvertTo>::value};
1578 const std::size_t
mx_count{subtype_count<ConvertTo>::value};
1588 std::vector<std::string>(
strings.begin(),
strings.begin() +
static_cast<std::ptrdiff_t
>(index)),
output);
1598template <
class AssignTo,
class ConvertTo, std::
size_t I>
1603 conditional<is_tuple_like<ConvertTo>::value,
typename std::tuple_element<I, ConvertTo>::type,
ConvertTo>::type;
1622 typename std::remove_const<typename std::tuple_element<0, typename ConvertTo::value_type>::type>::type
v1;
1623 typename std::tuple_element<1, typename ConvertTo::value_type>::type
v2;
1629 output.insert(
output.end(),
typename AssignTo::value_type{v1, v2});
1634 return (!
output.empty());
1647 "if the conversion type is defined as a tuple it must be the same size as the type you are converting to");
1662 std::vector<std::string>
temp;
1672 if(
static_cast<int>(
xcm) > type_count_min<ConvertTo>::value &&
is_separator(
temp.back())) {
1675 typename AssignTo::value_type
temp_out;
1693 std::is_assignable<ConvertTo &, ConvertTo>::value,
1700 typename ConvertTo::value_type
val;
1712 !std::is_assignable<AssignTo &, ConvertTo>::value,
1715 using ConvertType =
typename ConvertTo::value_type;
1743 tv =
static_cast<double>(
fv);
1752 std::ostringstream
out;
Definition TypeTools.hpp:96
static constexpr bool value
Definition TypeTools.hpp:103
Check for complex.
Definition TypeTools.hpp:235
static constexpr bool value
Definition TypeTools.hpp:242
Definition TypeTools.hpp:177
static constexpr bool value
Definition TypeTools.hpp:204
Check for input streamability.
Definition TypeTools.hpp:224
static constexpr bool value
Definition TypeTools.hpp:231
Definition TypeTools.hpp:213
static constexpr bool value
Definition TypeTools.hpp:220
Definition TypeTools.hpp:299
static constexpr bool value
Definition TypeTools.hpp:307
constexpr enabler dummy
An instance to use in EnableIf.
Definition TypeTools.hpp:39
auto to_string(T &&value) -> decltype(std::forward< T >(value))
Convert an object to a string (directly forward if this can become a string)
Definition TypeTools.hpp:312
auto checked_to_string(T &&value) -> decltype(to_string(std::forward< T >(value)))
special template overload
Definition TypeTools.hpp:368
return false
Definition TypeTools.hpp:927
bool is_separator(const std::string &str)
check if a string is a container segment separator (empty or "%%")
Definition StringTools.hpp:170
bool from_stream(const std::string &istring, T &obj)
Templated operation to get a value from a stream.
Definition TypeTools.hpp:247
constexpr int expected_max_vector_size
Definition StringTools.hpp:47
std::string value_string(const T &value)
get a string as a convertible value for arithmetic types
Definition TypeTools.hpp:382
std::string join(const T &v, std::string delim=",")
Simple function to join a string.
Definition StringTools.hpp:53
bool lexical_assign(const std::string &input, AssignTo &output)
Assign a value through lexical cast operations.
Definition TypeTools.hpp:1297
std::int64_t to_flag_value(std::string val) noexcept
Convert a flag into an integer value typically binary flags sets errno to nonzero if conversion faile...
Definition TypeTools.hpp:982
std::string to_lower(std::string str)
Return a lower case version of a string.
Definition StringTools.hpp:181
enabler
Simple empty scoped class.
Definition TypeTools.hpp:36
bool lexical_cast(const std::string &input, T &output)
Integer conversion.
Definition TypeTools.hpp:1034
bool integral_conversion(const std::string &input, T &output) noexcept
Convert to a signed integral.
Definition TypeTools.hpp:932
constexpr std::enable_if< I==type_count_base< T >::value, int >::type tuple_type_size()
0 if the index > tuple size
Definition TypeTools.hpp:472
typename make_void< Ts... >::type void_t
A copy of std::void_t from C++17 - same reasoning as enable_if_t, it does not hurt to redefine.
Definition TypeTools.hpp:55
typename std::enable_if< B, T >::type enable_if_t
Definition TypeTools.hpp:47
typename std::conditional< B, T, F >::type conditional_t
A copy of std::conditional_t from C++14 - same reasoning as enable_if_t, it does not hurt to redefine...
Definition TypeTools.hpp:58
CLI11_INLINE std::wstring widen(const std::string &str)
Convert a narrow string to a wide string.
std::string type
Definition TypeTools.hpp:87
This can be specialized to override the type deduction for IsMember.
Definition TypeTools.hpp:81
T type
Definition TypeTools.hpp:82
typename std::pointer_traits< T >::element_type type
Definition TypeTools.hpp:120
not a pointer
Definition TypeTools.hpp:115
T type
Definition TypeTools.hpp:116
Definition TypeTools.hpp:125
typename element_type< T >::type::value_type type
Definition TypeTools.hpp:126
Definition TypeTools.hpp:260
Definition TypeTools.hpp:280
Definition TypeTools.hpp:292
typename std::remove_const< typename value_type::first_type >::type first_type
Definition TypeTools.hpp:153
static auto first(Q &&pair_value) -> decltype(std::get< 0 >(std::forward< Q >(pair_value)))
Get the first value (really just the underlying value)
Definition TypeTools.hpp:157
static auto second(Q &&pair_value) -> decltype(std::get< 1 >(std::forward< Q >(pair_value)))
Get the second value (really just the underlying value)
Definition TypeTools.hpp:161
typename T::value_type value_type
Definition TypeTools.hpp:152
typename std::remove_const< typename value_type::second_type >::type second_type
Definition TypeTools.hpp:154
Adaptor for set-like structure: This just wraps a normal container in a few utilities that do almost ...
Definition TypeTools.hpp:130
typename T::value_type value_type
Definition TypeTools.hpp:131
typename std::remove_const< value_type >::type second_type
Definition TypeTools.hpp:133
static auto second(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the second value (really just the underlying value)
Definition TypeTools.hpp:140
typename std::remove_const< value_type >::type first_type
Definition TypeTools.hpp:132
static auto first(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the first value (really just the underlying value)
Definition TypeTools.hpp:136
forward declare the subtype_count_min structure
Definition TypeTools.hpp:437
Set of overloads to get the type size of an object.
Definition TypeTools.hpp:434
This will only trigger for actual void type.
Definition TypeTools.hpp:408
static const int value
Definition TypeTools.hpp:409
This will only trigger for actual void type.
Definition TypeTools.hpp:440
static const int value
Definition TypeTools.hpp:441
typename T::value_type type
Definition TypeTools.hpp:404
template to get the underlying value type if it exists or use a default
Definition TypeTools.hpp:398
def type
Definition TypeTools.hpp:399
Check to see if something is bool (fail check by default)
Definition TypeTools.hpp:61
Check to see if something is copyable pointer.
Definition TypeTools.hpp:76
static bool const value
Definition TypeTools.hpp:77
Check to see if something is a shared pointer.
Definition TypeTools.hpp:67
A copy of std::void_t from C++17 (helper for C++11 and C++14)
Definition TypeTools.hpp:50
void type
Definition TypeTools.hpp:51