45template <
bool B,
class T =
void>
using enable_if_t =
typename std::enable_if<B, T>::type;
56template <
bool B,
class T,
class F>
using conditional_t =
typename std::conditional<B, T, F>::type;
59template <
typename T>
struct is_bool : std::false_type {};
62template <>
struct is_bool<bool> : std::true_type {};
68template <
typename T>
struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
71template <
typename T>
struct is_shared_ptr<const std::shared_ptr<T>> : std::true_type {};
101 using type =
typename std::pointer_traits<T>::element_type;
111template <
typename T,
typename _ =
void>
struct pair_adaptor : std::false_type {
113 using first_type =
typename std::remove_const<value_type>::type;
134 using first_type =
typename std::remove_const<typename value_type::first_type>::type;
135 using second_type =
typename std::remove_const<typename value_type::second_type>::type;
139 return std::get<0>(std::forward<Q>(
pair_value));
143 return std::get<1>(std::forward<Q>(
pair_value));
154#pragma GCC diagnostic push
155#pragma GCC diagnostic ignored "-Wnarrowing"
159 template <
typename TT,
typename CC>
160 static auto test(
int, std::true_type) ->
decltype(
163#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
164#pragma nv_diag_suppress 2361
166#pragma diag_suppress 2361
169 TT{std::declval<CC>()}
171#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
172#pragma nv_diag_default 2361
174#pragma diag_default 2361
178 std::is_move_assignable<TT>());
180 template <
typename TT,
typename CC>
static auto test(
int, std::false_type) -> std::false_type;
182 template <
typename,
typename>
static auto test(...) -> std::false_type;
188#pragma GCC diagnostic pop
195 template <
typename TT,
typename SS>
196 static auto test(
int) ->
decltype(std::declval<SS &>() << std::declval<TT>(), std::true_type());
198 template <
typename,
typename>
static auto test(...) -> std::false_type;
206 template <
typename TT,
typename SS>
207 static auto test(
int) ->
decltype(std::declval<SS &>() >> std::declval<TT &>(), std::true_type());
209 template <
typename,
typename>
static auto test(...) -> std::false_type;
217 template <
typename TT>
218 static auto test(
int) ->
decltype(std::declval<TT>().real(), std::declval<TT>().imag(), std::true_type());
220 template <
typename>
static auto test(...) -> std::false_type;
229 std::istringstream
is;
232 return !
is.fail() && !
is.rdbuf()->in_avail();
252 decltype(std::declval<T>().clear()),
253 decltype(std::declval<T>().insert(std::declval<decltype(std::declval<T>().end())>(),
254 std::declval<const typename T::value_type &>()))>,
256 std::is_constructible<T, std::wstring>::value,
270 :
public std::true_type {};
273template <
typename T,
typename _ =
void>
struct is_wrapper : std::false_type {};
281 template <
typename SS>
284 static auto test(
int) ->
decltype(std::tuple_size<typename std::decay<SS>::type>
::value, std::true_type{});
285 template <
typename>
static auto test(...) -> std::false_type;
293auto to_string(T &&value) ->
decltype(std::forward<T>(value)) {
294 return std::forward<T>(value);
302 return std::string(value);
328 is_readable_container<T>::value,
345template <
typename T1,
350 return to_string(std::forward<T>(value));
354template <
typename T1,
359 return std::string{};
364 return std::to_string(value);
369 return std::to_string(
static_cast<typename std::underlying_type<T>::type
>(value));
379template <
typename T,
typename def,
typename Enable =
void>
struct wrapped_type {
385 using type =
typename T::value_type;
396 typename std::
enable_if<!is_tuple_like<T>::value && !is_mutable_container<T>::value &&
397 !std::is_void<T>::value>::type> {
404 static constexpr int value{std::tuple_size<T>::value};
421template <
typename T,
typename Enable =
void>
struct type_count {
428 typename std::
enable_if<!is_wrapper<T>::value && !is_tuple_like<T>::value && !is_complex<T>::value &&
429 !std::is_void<T>::value>::type> {
446 typename std::
enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value &&
447 !is_mutable_container<T>::value>::type> {
452template <
typename T, std::
size_t I>
453constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type
tuple_type_size() {
458template <
typename T, std::
size_t I>
459 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type
tuple_type_size() {
464template <
typename T>
struct type_count<T,
typename std::
enable_if<is_tuple_like<T>::value>::type> {
469template <
typename T>
struct subtype_count {
474template <
typename T,
typename Enable =
void>
struct type_count_min {
475 static const int value{0};
482 typename std::
enable_if<!is_mutable_container<T>::value && !is_tuple_like<T>::value && !is_wrapper<T>::value &&
483 !is_complex<T>::value && !std::is_void<T>::value>::type> {
489 static constexpr int value{1};
496 typename std::
enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value>::type> {
497 static constexpr int value{subtype_count_min<typename T::value_type>::value};
501template <
typename T, std::
size_t I>
502constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type
tuple_type_size_min() {
507template <
typename T, std::
size_t I>
508 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type
tuple_type_size_min() {
518template <
typename T>
struct subtype_count_min {
519 static constexpr int value{is_mutable_container<T>::value
525template <
typename T,
typename Enable =
void>
struct expected_count {
526 static const int value{0};
532 typename std::
enable_if<!is_mutable_container<T>::value && !is_wrapper<T>::value &&
533 !std::is_void<T>::value>::type> {
534 static constexpr int value{1};
544 static constexpr int value{expected_count<typename T::value_type>::value};
576 static constexpr object_category value{object_category::other};
583 typename std::
enable_if<std::is_integral<T>::value && !std::is_same<T, char>::value && std::is_signed<T>::value &&
584 !is_bool<T>::value && !std::is_enum<T>::value>::type> {
585 static constexpr object_category value{object_category::integral_value};
591 typename std::
enable_if<std::is_integral<T>::value && std::is_unsigned<T>::value &&
592 !std::is_same<T, char>::value && !is_bool<T>::value>::type> {
593 static constexpr object_category value{object_category::unsigned_integral};
599 static constexpr object_category value{object_category::char_value};
604 static constexpr object_category value{object_category::boolean_value};
609 static constexpr object_category value{object_category::floating_point};
614#define WIDE_STRING_CHECK \
615 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value
616#define STRING_CHECK true
618#define WIDE_STRING_CHECK true
619#define STRING_CHECK !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value
626 typename std::
enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value && WIDE_STRING_CHECK &&
627 std::is_assignable<T &, std::string>::value>::type> {
628 static constexpr object_category value{object_category::string_assignable};
635 typename std::
enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
636 !std::is_assignable<T &, std::string>::value && (type_count<T>::value == 1) &&
637 WIDE_STRING_CHECK && std::is_constructible<T, std::string>::value>::type> {
638 static constexpr object_category value{object_category::string_constructible};
644 typename std::
enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
645 STRING_CHECK && std::is_assignable<T &, std::wstring>::value>::type> {
646 static constexpr object_category value{object_category::wstring_assignable};
652 typename std::
enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
653 !std::is_assignable<T &, std::wstring>::value && (type_count<T>::value == 1) &&
654 STRING_CHECK && std::is_constructible<T, std::wstring>::value>::type> {
655 static constexpr object_category value{object_category::wstring_constructible};
660 static constexpr object_category value{object_category::enumeration};
664 static constexpr object_category value{object_category::complex_number};
670 using type =
typename std::conditional<
671 !std::is_floating_point<T>::value && !std::is_integral<T>::value &&
672 !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value &&
673 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value &&
674 !is_complex<T>::value && !is_mutable_container<T>::value && !std::is_enum<T>::value,
676 std::false_type>::type;
677 static constexpr bool value = type::value;
683 typename std::
enable_if<(!is_mutable_container<T>::value && is_wrapper<T>::value &&
684 !is_tuple_like<T>::value && uncommon_type<T>::value)>::type> {
685 static constexpr object_category value{object_category::wrapper_value};
692 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
693 is_direct_constructible<T, int>::value>::type> {
694 static constexpr object_category value{object_category::number_constructible};
701 !is_wrapper<T>::value && !is_direct_constructible<T, double>::value &&
702 is_direct_constructible<T, int>::value>::type> {
703 static constexpr object_category value{object_category::integer_constructible};
710 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
711 !is_direct_constructible<T, int>::value>::type> {
712 static constexpr object_category value{object_category::double_constructible};
720 ((type_count<T>::value >= 2 && !is_wrapper<T>::value) ||
721 (uncommon_type<T>::value && !is_direct_constructible<T, double>::value &&
722 !is_direct_constructible<T, int>::value) ||
723 (uncommon_type<T>::value && type_count<T>::value >= 2))>::type> {
724 static constexpr object_category value{object_category::tuple_value};
734 static constexpr object_category value{object_category::container_value};
745constexpr const char *type_name() {
751 classify_object<T>::value == object_category::integer_constructible,
753constexpr const char *type_name() {
759constexpr const char *type_name() {
765 classify_object<T>::value == object_category::number_constructible ||
766 classify_object<T>::value == object_category::double_constructible,
768constexpr const char *type_name() {
775constexpr const char *type_name() {
782constexpr const char *type_name() {
789constexpr const char *type_name() {
796 classify_object<T>::value <= object_category::other,
798constexpr const char *type_name() {
805std::string type_name();
810 classify_object<T>::value == object_category::wrapper_value,
812std::string type_name();
818inline std::string type_name() {
823template <
typename T, std::
size_t I>
824inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type
tuple_name() {
825 return std::string{};
829template <
typename T, std::
size_t I>
833 if(
str.back() ==
',')
842inline std::string type_name() {
844 tname.push_back(
']');
851 classify_object<T>::value == object_category::wrapper_value,
853inline std::string type_name() {
882 if(
input.find_first_of(
"_'") != std::string::npos) {
888 if(
input.compare(0, 2,
"0o") == 0) {
898 if(
input.compare(0, 2,
"0b") == 0) {
927 if(
input ==
"true") {
929 output =
static_cast<T
>(1);
933 if(
input.find_first_of(
"_'") != std::string::npos) {
939 if(
input.compare(0, 2,
"0o") == 0) {
949 if(
input.compare(0, 2,
"0b") == 0) {
973 std::int64_t
ret = 0;
974 if(
val.size() == 1) {
975 if(
val[0] >=
'1' &&
val[0] <=
'9') {
976 return (
static_cast<std::int64_t
>(
val[0]) -
'0');
1011template <
typename T,
1013 classify_object<T>::value == object_category::unsigned_integral,
1020template <
typename T,
1023 if(
input.size() == 1) {
1031template <
typename T,
1047template <
typename T,
1053 char *
val =
nullptr;
1060 if(
input.find_first_of(
"_'") != std::string::npos) {
1070template <
typename T,
1077 auto nloc =
str1.find_last_of(
"+-");
1078 if(
nloc != std::string::npos &&
nloc > 0) {
1081 if(
str1.back() ==
'i' ||
str1.back() ==
'j')
1085 if(
str1.back() ==
'i' ||
str1.back() ==
'j') {
1102template <
typename T,
1136template <
typename T,
1139 typename std::underlying_type<T>::type
val;
1148template <
typename T,
1150 std::is_assignable<T &, typename T::value_type>::value,
1153 typename T::value_type
val;
1161template <
typename T,
1163 !std::is_assignable<T &, typename T::value_type>::value && std::is_assignable<T &, T>::value,
1166 typename T::value_type
val;
1221template <
typename T,
1228#pragma warning(push)
1229#pragma warning(disable : 4800)
1247template <
typename T,
1252 "option object type must have a lexical cast overload or streaming input operator(>>) defined, if it "
1253 "is convertible from another type use the add_option<T, XC>(...) with XC being the known type");
1262 (classify_object<AssignTo>::value == object_category::string_assignable ||
1263 classify_object<AssignTo>::value == object_category::string_constructible ||
1264 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1265 classify_object<AssignTo>::value == object_category::wstring_constructible),
1275 classify_object<AssignTo>::value != object_category::string_assignable &&
1276 classify_object<AssignTo>::value != object_category::string_constructible &&
1277 classify_object<AssignTo>::value != object_category::wstring_assignable &&
1278 classify_object<AssignTo>::value != object_category::wstring_constructible,
1293 classify_object<AssignTo>::value == object_category::wrapper_value,
1297 typename AssignTo::value_type
emptyVal{};
1309 classify_object<AssignTo>::value != object_category::wrapper_value &&
1310 std::is_assignable<AssignTo &, int>::value,
1319#if defined(__clang__)
1321#pragma clang diagnostic push
1322#pragma clang diagnostic ignored "-Wsign-conversion"
1325#if defined(__clang__)
1326#pragma clang diagnostic pop
1352 std::is_move_assignable<AssignTo>::value,
1367 classify_object<AssignTo>::value <= object_category::wrapper_value,
1382 using FirstType =
typename std::remove_const<typename std::tuple_element<0, ConvertTo>::type>::type;
1383 using SecondType =
typename std::tuple_element<1, ConvertTo>::type;
1413 typename AssignTo::value_type
out;
1423 return (!
output.empty());
1434 if(
str1.back() ==
'i' ||
str1.back() ==
'j') {
1498 classify_object<ConvertTo>::value != object_category::wrapper_value &&
1514template <
class AssignTo,
class ConvertTo, std::
size_t I>
1521template <
class AssignTo,
class ConvertTo>
1530template <
class AssignTo,
class ConvertTo>
1541template <
class AssignTo,
class ConvertTo>
1542inline typename std::enable_if<is_mutable_container<ConvertTo>::value ||
1547 std::size_t index{subtype_count_min<ConvertTo>::value};
1548 const std::size_t
mx_count{subtype_count<ConvertTo>::value};
1558 std::vector<std::string>(
strings.begin(),
strings.begin() +
static_cast<std::ptrdiff_t
>(index)),
output);
1568template <
class AssignTo,
class ConvertTo, std::
size_t I>
1573 conditional<is_tuple_like<ConvertTo>::value,
typename std::tuple_element<I, ConvertTo>::type,
ConvertTo>::type;
1592 typename std::remove_const<typename std::tuple_element<0, typename ConvertTo::value_type>::type>::type
v1;
1593 typename std::tuple_element<1, typename ConvertTo::value_type>::type
v2;
1599 output.insert(
output.end(),
typename AssignTo::value_type{v1, v2});
1604 return (!
output.empty());
1617 "if the conversion type is defined as a tuple it must be the same size as the type you are converting to");
1632 std::vector<std::string>
temp;
1642 if(
static_cast<int>(
xcm) > type_count_min<ConvertTo>::value &&
is_separator(
temp.back())) {
1645 typename AssignTo::value_type
temp_out;
1663 std::is_assignable<ConvertTo &, ConvertTo>::value,
1670 typename ConvertTo::value_type
val;
1682 !std::is_assignable<AssignTo &, ConvertTo>::value,
1685 using ConvertType =
typename ConvertTo::value_type;
1713 tv =
static_cast<double>(
fv);
1722 std::ostringstream
out;
Check for complex.
Definition TypeTools.hpp:216
static constexpr bool value
Definition TypeTools.hpp:223
Definition TypeTools.hpp:158
static constexpr bool value
Definition TypeTools.hpp:185
Check for input streamability.
Definition TypeTools.hpp:205
static constexpr bool value
Definition TypeTools.hpp:212
Definition TypeTools.hpp:194
static constexpr bool value
Definition TypeTools.hpp:201
Definition TypeTools.hpp:280
static constexpr bool value
Definition TypeTools.hpp:288
constexpr enabler dummy
An instance to use in EnableIf.
Definition TypeTools.hpp:37
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:293
auto checked_to_string(T &&value) -> decltype(to_string(std::forward< T >(value)))
special template overload
Definition TypeTools.hpp:349
return false
Definition TypeTools.hpp:908
bool is_separator(const std::string &str)
check if a string is a container segment separator (empty or "%%")
Definition StringTools.hpp:168
bool from_stream(const std::string &istring, T &obj)
Templated operation to get a value from a stream.
Definition TypeTools.hpp:228
constexpr int expected_max_vector_size
Definition StringTools.hpp:45
std::string value_string(const T &value)
get a string as a convertible value for arithmetic types
Definition TypeTools.hpp:363
std::string join(const T &v, std::string delim=",")
Simple function to join a string.
Definition StringTools.hpp:51
bool lexical_assign(const std::string &input, AssignTo &output)
Assign a value through lexical cast operations.
Definition TypeTools.hpp:1267
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:963
std::string to_lower(std::string str)
Return a lower case version of a string.
Definition StringTools.hpp:179
enabler
Simple empty scoped class.
Definition TypeTools.hpp:34
bool lexical_cast(const std::string &input, T &output)
Integer conversion.
Definition TypeTools.hpp:1015
bool integral_conversion(const std::string &input, T &output) noexcept
Convert to a signed integral.
Definition TypeTools.hpp:913
constexpr std::enable_if< I==type_count_base< T >::value, int >::type tuple_type_size()
0 if the index > tuple size
Definition TypeTools.hpp:453
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:53
typename std::enable_if< B, T >::type enable_if_t
Definition TypeTools.hpp:45
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:56
CLI11_INLINE std::wstring widen(const std::string &str)
Convert a narrow string to a wide string.
std::string type
Definition TypeTools.hpp:85
This can be specialized to override the type deduction for IsMember.
Definition TypeTools.hpp:79
T type
Definition TypeTools.hpp:80
typename std::pointer_traits< T >::element_type type
Definition TypeTools.hpp:101
not a pointer
Definition TypeTools.hpp:96
T type
Definition TypeTools.hpp:97
Definition TypeTools.hpp:106
typename element_type< T >::type::value_type type
Definition TypeTools.hpp:107
Definition TypeTools.hpp:241
Definition TypeTools.hpp:261
Definition TypeTools.hpp:273
typename std::remove_const< typename value_type::first_type >::type first_type
Definition TypeTools.hpp:134
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:138
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:142
typename T::value_type value_type
Definition TypeTools.hpp:133
typename std::remove_const< typename value_type::second_type >::type second_type
Definition TypeTools.hpp:135
Adaptor for set-like structure: This just wraps a normal container in a few utilities that do almost ...
Definition TypeTools.hpp:111
typename T::value_type value_type
Definition TypeTools.hpp:112
typename std::remove_const< value_type >::type second_type
Definition TypeTools.hpp:114
static auto second(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the second value (really just the underlying value)
Definition TypeTools.hpp:121
typename std::remove_const< value_type >::type first_type
Definition TypeTools.hpp:113
static auto first(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the first value (really just the underlying value)
Definition TypeTools.hpp:117
forward declare the subtype_count_min structure
Definition TypeTools.hpp:418
Set of overloads to get the type size of an object.
Definition TypeTools.hpp:415
This will only trigger for actual void type.
Definition TypeTools.hpp:389
static const int value
Definition TypeTools.hpp:390
This will only trigger for actual void type.
Definition TypeTools.hpp:421
static const int value
Definition TypeTools.hpp:422
typename T::value_type type
Definition TypeTools.hpp:385
template to get the underlying value type if it exists or use a default
Definition TypeTools.hpp:379
def type
Definition TypeTools.hpp:380
Check to see if something is bool (fail check by default)
Definition TypeTools.hpp:59
Check to see if something is copyable pointer.
Definition TypeTools.hpp:74
static bool const value
Definition TypeTools.hpp:75
Check to see if something is a shared pointer.
Definition TypeTools.hpp:65
A copy of std::void_t from C++17 (helper for C++11 and C++14)
Definition TypeTools.hpp:48
void type
Definition TypeTools.hpp:49