19 #include <type_traits>
47 template <
bool B,
class T =
void>
using enable_if_t =
typename std::enable_if<B, T>::type;
58 template <
bool B,
class T,
class F>
using conditional_t =
typename std::conditional<B, T, F>::type;
61 template <
typename T>
struct is_bool : std::false_type {};
64 template <>
struct is_bool<bool> : std::true_type {};
73 template <
typename T>
struct is_shared_ptr<const
std::shared_ptr<T>> : std::true_type {};
90 namespace adl_detail {
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;
103 static constexpr
bool value = decltype(test<T, S>(0))::value;
120 using type =
typename std::pointer_traits<T>::element_type;
130 template <
typename T,
typename _ =
void>
struct pair_adaptor : std::false_type {
132 using first_type =
typename std::remove_const<value_type>::type;
136 template <
typename Q>
static auto first(Q &&pair_value) -> decltype(std::forward<Q>(pair_value)) {
137 return std::forward<Q>(pair_value);
140 template <
typename Q>
static auto second(Q &&pair_value) -> decltype(std::forward<Q>(pair_value)) {
141 return std::forward<Q>(pair_value);
147 template <
typename T>
150 conditional_t<false, void_t<typename T::value_type::first_type, typename T::value_type::second_type>, void>>
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;
157 template <
typename Q>
static auto first(Q &&pair_value) -> decltype(std::get<0>(std::forward<Q>(pair_value))) {
158 return std::get<0>(std::forward<Q>(pair_value));
161 template <
typename Q>
static auto second(Q &&pair_value) -> decltype(std::get<1>(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;
204 static constexpr
bool value = decltype(test<T, C>(0,
typename std::is_constructible<T, C>::type()))::value;
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;
220 static constexpr
bool value = decltype(test<T, S>(0))::value;
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;
231 static constexpr
bool value = decltype(test<T, S>(0))::value;
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;
242 static constexpr
bool value = decltype(test<T>(0))::value;
248 std::istringstream is;
251 return !is.fail() && !is.rdbuf()->in_avail();
254 template <typename T, enable_if_t<!is_istreamable<T>::value, detail::enabler> =
detail::dummy>
265 template <
typename T>
269 void_t<typename T::value_type,
270 decltype(std::declval<T>().end()),
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 &>()))>,
274 void>> :
public conditional_t<std::is_constructible<T, std::string>::value ||
275 std::is_constructible<T, std::wstring>::value,
284 template <
typename T>
287 conditional_t<false, void_t<decltype(
std::declval<T>().end()), decltype(std::declval<T>().begin())>, void>>
288 :
public std::true_type {};
291 template <
typename T,
typename _ =
void>
struct is_wrapper : std::false_type {};
294 template <
typename T>
295 struct is_wrapper<T, conditional_t<false, void_t<typename T::value_type>, void>> :
public std::true_type {};
300 template <typename SS, enable_if_t<!is_complex<SS>::value, detail::enabler> =
detail::dummy>
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;
307 static constexpr
bool value = decltype(test<S>(0))::value;
312 static const int value{0};
316 template <
typename T>
318 typename
std::enable_if<!is_tuple_like<T>::value && !is_mutable_container<T>::value &&
319 !std::is_void<T>::value>::type> {
320 static constexpr
int value{1};
324 template <
typename T>
325 struct type_count_base<T, typename
std::enable_if<is_tuple_like<T>::value && !is_mutable_container<T>::value>::type> {
326 static constexpr
int value{
327 std::tuple_size<typename std::decay<T>::type>
::value};
331 template <
typename T>
struct type_count_base<T, typename
std::enable_if<is_mutable_container<T>::value>::type> {
336 template <typename T, enable_if_t<std::is_convertible<T, std::string>::value, detail::enabler> =
detail::dummy>
337 auto to_string(T &&value) -> decltype(std::forward<T>(value)) {
338 return std::forward<T>(
value);
342 template <
typename T,
346 return std::string(value);
350 template <
typename T,
352 is_ostreamable<T>::value,
355 std::stringstream stream;
363 template <
typename T,
364 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
365 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value == 1,
370 template <
typename T,
371 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
372 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value >= 2,
379 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
380 !is_ostreamable<T>::value && !is_readable_container<typename std::remove_const<T>::type>
::value &&
381 !is_tuple_like<T>::value,
388 template <
typename T,
389 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
390 !is_ostreamable<T>::value && is_readable_container<T>::value && !is_tuple_like<T>::value,
392 inline std::string
to_string(T &&variable) {
393 auto cval = variable.begin();
394 auto end = variable.end();
398 std::vector<std::string> defaults;
409 template <
typename T, std::
size_t I>
410 inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type
tuple_value_string(T && );
413 template <
typename T, std::
size_t I>
414 inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type
tuple_value_string(T &&value);
417 template <
typename T,
418 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
419 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value == 1,
421 inline std::string
to_string(T &&value) {
426 template <
typename T,
427 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
428 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value >= 2,
431 auto tname = std::string(1,
'[') + tuple_value_string<T, 0>(
value);
432 tname.push_back(
']');
437 template <
typename T, std::
size_t I>
438 inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type
tuple_value_string(T && ) {
439 return std::string{};
443 template <
typename T, std::
size_t I>
444 inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type
tuple_value_string(T &&value) {
445 auto str = std::string{
to_string(std::get<I>(value))} +
',' + tuple_value_string<T, I + 1>(
value);
446 if(str.back() ==
',')
452 template <
typename T1,
457 return to_string(std::forward<T>(value));
461 template <
typename T1,
466 return std::string{};
469 template <typename T, enable_if_t<std::is_arithmetic<T>::value, detail::enabler> =
detail::dummy>
474 template <typename T, enable_if_t<std::is_enum<T>::value, detail::enabler> =
detail::dummy>
476 return std::to_string(
static_cast<typename std::underlying_type<T>::type
>(value));
479 template <
typename T,
480 enable_if_t<!std::is_enum<T>::value && !std::is_arithmetic<T>::value, detail::enabler> =
detail::dummy>
486 template <
typename T,
typename def,
typename Enable =
void>
struct wrapped_type {
491 template <
typename T,
typename def>
struct wrapped_type<T, def, typename
std::enable_if<is_wrapper<T>::value>
::type> {
492 using type =
typename T::value_type;
504 template <
typename T,
typename Enable =
void>
struct type_count {
505 static const int value{0};
509 template <
typename T>
511 typename
std::enable_if<!is_wrapper<T>::value && !is_tuple_like<T>::value && !is_complex<T>::value &&
512 !std::is_void<T>::value>::type> {
513 static constexpr
int value{1};
517 template <
typename T>
struct type_count<T, typename
std::enable_if<is_complex<T>::value>::type> {
518 static constexpr
int value{2};
522 template <
typename T>
struct type_count<T, typename
std::enable_if<is_mutable_container<T>::value>::type> {
527 template <
typename T>
529 typename
std::enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value &&
530 !is_mutable_container<T>::value>::type> {
535 template <
typename T, std::
size_t I>
536 constexpr
typename std::enable_if<I == type_count_base<T>::value,
int>::type
tuple_type_size() {
541 template <
typename T, std::
size_t I>
542 constexpr
typename std::enable_if < I<type_count_base<T>::value,
int>::type
tuple_type_size() {
543 return subtype_count<typename std::tuple_element<I, T>::type>
::value + tuple_type_size<T, I + 1>();
547 template <
typename T>
548 struct type_count<T, typename
std::enable_if<is_tuple_like<T>::value && !is_complex<T>::value>::type> {
549 static constexpr
int value{tuple_type_size<T, 0>()};
553 template <
typename T>
struct subtype_count {
558 template <
typename T,
typename Enable =
void>
struct type_count_min {
559 static const int value{0};
563 template <
typename T>
564 struct type_count_min<
566 typename
std::enable_if<!is_mutable_container<T>::value && !is_tuple_like<T>::value && !is_wrapper<T>::value &&
567 !is_complex<T>::value && !std::is_void<T>::value>::type> {
568 static constexpr
int value{type_count<T>::value};
572 template <
typename T>
struct type_count_min<T, typename
std::enable_if<is_complex<T>::value>::type> {
573 static constexpr
int value{1};
577 template <
typename T>
578 struct type_count_min<
580 typename
std::enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value>::type> {
581 static constexpr
int value{subtype_count_min<typename T::value_type>::value};
585 template <
typename T, std::
size_t I>
586 constexpr
typename std::enable_if<I == type_count_base<T>::value,
int>::type tuple_type_size_min() {
591 template <
typename T, std::
size_t I>
592 constexpr
typename std::enable_if < I<type_count_base<T>::value,
int>::type tuple_type_size_min() {
593 return subtype_count_min<typename std::tuple_element<I, T>::type>
::value + tuple_type_size_min<T, I + 1>();
597 template <
typename T>
598 struct type_count_min<T, typename
std::enable_if<is_tuple_like<T>::value && !is_complex<T>::value>::type> {
599 static constexpr
int value{tuple_type_size_min<T, 0>()};
603 template <
typename T>
struct subtype_count_min {
604 static constexpr
int value{is_mutable_container<T>::value
606 : type_count_min<T>::value};
610 template <
typename T,
typename Enable =
void>
struct expected_count {
611 static const int value{0};
615 template <
typename T>
616 struct expected_count<T,
617 typename
std::enable_if<!is_mutable_container<T>::value && !is_wrapper<T>::value &&
618 !std::is_void<T>::value>::type> {
619 static constexpr
int value{1};
622 template <
typename T>
struct expected_count<T, typename
std::enable_if<is_mutable_container<T>::value>::type> {
627 template <
typename T>
628 struct expected_count<T, typename
std::enable_if<!is_mutable_container<T>::value && is_wrapper<T>::value>::type> {
629 static constexpr
int value{expected_count<typename T::value_type>::value};
633 enum class object_category : std::uint8_t {
636 unsigned_integral = 4,
640 number_constructible = 12,
641 double_constructible = 14,
642 integer_constructible = 16,
644 string_assignable = 23,
645 string_constructible = 24,
646 wstring_assignable = 25,
647 wstring_constructible = 26,
653 container_value = 80,
660 template <
typename T,
typename Enable =
void>
struct classify_object {
661 static constexpr object_category value{object_category::other};
665 template <
typename T>
666 struct classify_object<
668 typename
std::enable_if<std::is_integral<T>::value && !std::is_same<T, char>::value && std::is_signed<T>::value &&
669 !is_bool<T>::value && !std::is_enum<T>::value>::type> {
670 static constexpr object_category value{object_category::integral_value};
674 template <
typename T>
675 struct classify_object<T,
676 typename
std::enable_if<std::is_integral<T>::value && std::is_unsigned<T>::value &&
677 !std::is_same<T, char>::value && !is_bool<T>::value>::type> {
678 static constexpr object_category value{object_category::unsigned_integral};
682 template <
typename T>
683 struct classify_object<T, typename
std::enable_if<std::is_same<T, char>::value && !std::is_enum<T>::value>::type> {
684 static constexpr object_category value{object_category::char_value};
688 template <
typename T>
struct classify_object<T, typename
std::enable_if<is_bool<T>::value>::type> {
689 static constexpr object_category value{object_category::boolean_value};
693 template <
typename T>
struct classify_object<T, typename
std::enable_if<std::is_floating_point<T>::value>::type> {
694 static constexpr object_category value{object_category::floating_point};
699 #define WIDE_STRING_CHECK \
700 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value
701 #define STRING_CHECK true
703 #define WIDE_STRING_CHECK true
704 #define STRING_CHECK !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value
708 template <
typename T>
709 struct classify_object<
711 typename
std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value && WIDE_STRING_CHECK &&
712 std::is_assignable<T &, std::string>::value>::type> {
713 static constexpr object_category value{object_category::string_assignable};
717 template <
typename T>
718 struct classify_object<
720 typename
std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
721 !std::is_assignable<T &, std::string>::value && (type_count<T>::value == 1) &&
722 WIDE_STRING_CHECK && std::is_constructible<T, std::string>::value>::type> {
723 static constexpr object_category value{object_category::string_constructible};
727 template <
typename T>
728 struct classify_object<T,
729 typename
std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
730 STRING_CHECK && std::is_assignable<T &, std::wstring>::value>::type> {
731 static constexpr object_category value{object_category::wstring_assignable};
734 template <
typename T>
735 struct classify_object<
737 typename
std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
738 !std::is_assignable<T &, std::wstring>::value && (type_count<T>::value == 1) &&
739 STRING_CHECK && std::is_constructible<T, std::wstring>::value>::type> {
740 static constexpr object_category value{object_category::wstring_constructible};
744 template <
typename T>
struct classify_object<T, typename
std::enable_if<std::is_enum<T>::value>::type> {
745 static constexpr object_category value{object_category::enumeration};
748 template <
typename T>
struct classify_object<T, typename
std::enable_if<is_complex<T>::value>::type> {
749 static constexpr object_category value{object_category::complex_number};
754 template <
typename T>
struct uncommon_type {
755 using type =
typename std::conditional<
756 !std::is_floating_point<T>::value && !std::is_integral<T>::value &&
757 !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value &&
758 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value &&
759 !is_complex<T>::value && !is_mutable_container<T>::value && !std::is_enum<T>::value,
761 std::false_type>::type;
762 static constexpr
bool value = type::value;
766 template <
typename T>
767 struct classify_object<T,
768 typename
std::enable_if<(!is_mutable_container<T>::value && is_wrapper<T>::value &&
769 !is_tuple_like<T>::value && uncommon_type<T>::value)>::type> {
770 static constexpr object_category value{object_category::wrapper_value};
774 template <
typename T>
775 struct classify_object<T,
776 typename
std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
777 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
778 is_direct_constructible<T, int>::value>::type> {
779 static constexpr object_category value{object_category::number_constructible};
783 template <
typename T>
784 struct classify_object<T,
785 typename
std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
786 !is_wrapper<T>::value && !is_direct_constructible<T, double>::value &&
787 is_direct_constructible<T, int>::value>::type> {
788 static constexpr object_category value{object_category::integer_constructible};
792 template <
typename T>
793 struct classify_object<T,
794 typename
std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
795 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
796 !is_direct_constructible<T, int>::value>::type> {
797 static constexpr object_category value{object_category::double_constructible};
801 template <
typename T>
802 struct classify_object<
804 typename
std::enable_if<is_tuple_like<T>::value &&
805 ((type_count<T>::value >= 2 && !is_wrapper<T>::value) ||
806 (uncommon_type<T>::value && !is_direct_constructible<T, double>::value &&
807 !is_direct_constructible<T, int>::value) ||
808 (uncommon_type<T>::value && type_count<T>::value >= 2))>::type> {
809 static constexpr object_category value{object_category::tuple_value};
818 template <
typename T>
struct classify_object<T, typename
std::enable_if<is_mutable_container<T>::value>::type> {
819 static constexpr object_category value{object_category::container_value};
828 template <
typename T,
829 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> =
detail::dummy>
834 template <
typename T,
835 enable_if_t<classify_object<T>::value == object_category::integral_value ||
836 classify_object<T>::value == object_category::integer_constructible,
842 template <
typename T,
843 enable_if_t<classify_object<T>::value == object_category::unsigned_integral, detail::enabler> =
detail::dummy>
848 template <
typename T,
849 enable_if_t<classify_object<T>::value == object_category::floating_point ||
850 classify_object<T>::value == object_category::number_constructible ||
851 classify_object<T>::value == object_category::double_constructible,
858 template <
typename T,
859 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> =
detail::dummy>
865 template <
typename T,
866 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> =
detail::dummy>
872 template <
typename T,
873 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> =
detail::dummy>
879 template <
typename T,
880 enable_if_t<classify_object<T>::value >= object_category::string_assignable &&
881 classify_object<T>::value <= object_category::other,
887 template <
typename T,
888 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value >= 2,
893 template <
typename T,
894 enable_if_t<classify_object<T>::value == object_category::container_value ||
895 classify_object<T>::value == object_category::wrapper_value,
900 template <
typename T,
901 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value == 1,
904 return type_name<typename std::decay<typename std::tuple_element<0, T>::type>::type>();
908 template <
typename T, std::
size_t I>
909 inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_name() {
910 return std::string{};
914 template <
typename T, std::
size_t I>
915 inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_name() {
916 auto str = std::string{type_name<typename std::decay<typename std::tuple_element<I, T>::type>::type>()} +
',' +
917 tuple_name<T, I + 1>();
918 if(str.back() ==
',')
924 template <
typename T,
925 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value >= 2,
928 auto tname = std::string(1,
'[') + tuple_name<T, 0>();
929 tname.push_back(
']');
934 template <
typename T,
935 enable_if_t<classify_object<T>::value == object_category::container_value ||
936 classify_object<T>::value == object_category::wrapper_value,
939 return type_name<typename T::value_type>();
945 template <typename T, enable_if_t<std::is_unsigned<T>::value, detail::enabler> =
detail::dummy>
947 if(input.empty() || input.front() ==
'-') {
952 std::uint64_t output_ll = std::strtoull(input.c_str(), &val, 0);
953 if(errno == ERANGE) {
956 output =
static_cast<T
>(output_ll);
957 if(val == (input.c_str() + input.size()) && static_cast<std::uint64_t>(output) == output_ll) {
961 std::int64_t output_sll = std::strtoll(input.c_str(), &val, 0);
962 if(val == (input.c_str() + input.size())) {
963 output = (output_sll < 0) ? static_cast<T>(0) : static_cast<T>(output_sll);
964 return (static_cast<std::int64_t>(output) == output_sll);
968 if(input.find_first_of(group_separators) != std::string::npos) {
969 std::string nstring = input;
970 for(
auto &separator : group_separators) {
971 if(input.find_first_of(separator) != std::string::npos) {
972 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
978 if(std::isspace(static_cast<unsigned char>(input.back()))) {
981 if(input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0) {
984 output_ll = std::strtoull(input.c_str() + 2, &val, 8);
985 if(errno == ERANGE) {
988 output =
static_cast<T
>(output_ll);
989 return (val == (input.c_str() + input.size()) && static_cast<std::uint64_t>(output) == output_ll);
991 if(input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0) {
997 output_ll = std::strtoull(input.c_str() + 2, &val, 2);
998 if(errno == ERANGE) {
1001 output =
static_cast<T
>(output_ll);
1002 return (val == (input.c_str() + input.size()) && static_cast<std::uint64_t>(output) == output_ll);
1009 template <typename T, enable_if_t<std::is_signed<T>::value, detail::enabler> =
detail::dummy>
1014 char *val =
nullptr;
1016 std::int64_t output_ll = std::strtoll(input.c_str(), &val, 0);
1017 if(errno == ERANGE) {
1020 output =
static_cast<T
>(output_ll);
1021 if(val == (input.c_str() + input.size()) && static_cast<std::int64_t>(output) == output_ll) {
1024 if(input ==
"true") {
1026 output =
static_cast<T
>(1);
1031 if(input.find_first_of(group_separators) != std::string::npos) {
1032 for(
auto &separator : group_separators) {
1033 if(input.find_first_of(separator) != std::string::npos) {
1034 std::string nstring = input;
1035 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1040 if(std::isspace(static_cast<unsigned char>(input.back()))) {
1043 if(input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0) {
1046 output_ll = std::strtoll(input.c_str() + 2, &val, 8);
1047 if(errno == ERANGE) {
1050 output =
static_cast<T
>(output_ll);
1051 return (val == (input.c_str() + input.size()) && static_cast<std::int64_t>(output) == output_ll);
1053 if(input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0) {
1059 output_ll = std::strtoll(input.c_str() + 2, &val, 2);
1060 if(errno == ERANGE) {
1063 output =
static_cast<T
>(output_ll);
1064 return (val == (input.c_str() + input.size()) && static_cast<std::int64_t>(output) == output_ll);
1072 static const std::string trueString(
"true");
1073 static const std::string falseString(
"false");
1074 if(val == trueString) {
1077 if(val == falseString) {
1081 std::int64_t ret = 0;
1082 if(val.size() == 1) {
1083 if(val[0] >=
'1' && val[0] <=
'9') {
1084 return (static_cast<std::int64_t>(val[0]) -
'0');
1104 if(val == trueString || val ==
"on" || val ==
"yes" || val ==
"enable") {
1106 }
else if(val == falseString || val ==
"off" || val ==
"no" || val ==
"disable") {
1109 char *loc_ptr{
nullptr};
1110 ret = std::strtoll(val.c_str(), &loc_ptr, 0);
1111 if(loc_ptr != (val.c_str() + val.size()) && errno == 0) {
1119 template <
typename T,
1120 enable_if_t<classify_object<T>::value == object_category::integral_value ||
1121 classify_object<T>::value == object_category::unsigned_integral,
1128 template <
typename T,
1129 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> =
detail::dummy>
1130 bool lexical_cast(
const std::string &input, T &output) {
1131 if(input.size() == 1) {
1132 output =
static_cast<T
>(input[0]);
1140 output =
static_cast<T
>(res);
1146 template <
typename T,
1147 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> =
detail::dummy>
1148 bool lexical_cast(
const std::string &input, T &output) {
1153 }
else if(errno == ERANGE) {
1154 output = (input[0] !=
'-');
1162 template <
typename T,
1163 enable_if_t<classify_object<T>::value == object_category::floating_point, detail::enabler> =
detail::dummy>
1164 bool lexical_cast(
const std::string &input, T &output) {
1168 char *val =
nullptr;
1169 auto output_ld = std::strtold(input.c_str(), &val);
1170 output =
static_cast<T
>(output_ld);
1171 if(val == (input.c_str() + input.size())) {
1174 while(std::isspace(static_cast<unsigned char>(*val))) {
1176 if(val == (input.c_str() + input.size())) {
1183 if(input.find_first_of(group_separators) != std::string::npos) {
1184 for(
auto &separator : group_separators) {
1185 if(input.find_first_of(separator) != std::string::npos) {
1186 std::string nstring = input;
1187 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1196 template <
typename T,
1197 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> =
detail::dummy>
1198 bool lexical_cast(
const std::string &input, T &output) {
1199 using XC =
typename wrapped_type<T, double>::type;
1202 bool worked =
false;
1203 auto nloc = str1.find_last_of(
"+-");
1204 if(nloc != std::string::npos && nloc > 0) {
1206 str1 = str1.substr(nloc);
1207 if(str1.back() ==
'i' || str1.back() ==
'j')
1211 if(str1.back() ==
'i' || str1.back() ==
'j') {
1228 template <
typename T,
1229 enable_if_t<classify_object<T>::value == object_category::string_assignable, detail::enabler> =
detail::dummy>
1230 bool lexical_cast(
const std::string &input, T &output) {
1238 enable_if_t<classify_object<T>::value == object_category::string_constructible, detail::enabler> =
detail::dummy>
1239 bool lexical_cast(
const std::string &input, T &output) {
1247 enable_if_t<classify_object<T>::value == object_category::wstring_assignable, detail::enabler> =
detail::dummy>
1248 bool lexical_cast(
const std::string &input, T &output) {
1249 output =
widen(input);
1255 enable_if_t<classify_object<T>::value == object_category::wstring_constructible, detail::enabler> =
detail::dummy>
1256 bool lexical_cast(
const std::string &input, T &output) {
1257 output = T{
widen(input)};
1262 template <
typename T,
1263 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> =
detail::dummy>
1264 bool lexical_cast(
const std::string &input, T &output) {
1265 typename std::underlying_type<T>::type val;
1269 output =
static_cast<T
>(val);
1274 template <
typename T,
1275 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1276 std::is_assignable<T &, typename T::value_type>::value,
1278 bool lexical_cast(
const std::string &input, T &output) {
1279 typename T::value_type val;
1287 template <
typename T,
1288 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1289 !std::is_assignable<T &, typename T::value_type>::value && std::is_assignable<T &, T>::value,
1291 bool lexical_cast(
const std::string &input, T &output) {
1292 typename T::value_type val;
1303 enable_if_t<classify_object<T>::value == object_category::number_constructible, detail::enabler> =
detail::dummy>
1304 bool lexical_cast(
const std::string &input, T &output) {
1323 enable_if_t<classify_object<T>::value == object_category::integer_constructible, detail::enabler> =
detail::dummy>
1324 bool lexical_cast(
const std::string &input, T &output) {
1336 enable_if_t<classify_object<T>::value == object_category::double_constructible, detail::enabler> =
detail::dummy>
1337 bool lexical_cast(
const std::string &input, T &output) {
1347 template <
typename T,
1348 enable_if_t<classify_object<T>::value == object_category::other && std::is_assignable<T &, int>::value,
1350 bool lexical_cast(
const std::string &input, T &output) {
1354 #pragma warning(push)
1355 #pragma warning(disable : 4800)
1361 #pragma warning(pop)
1373 template <
typename T,
1374 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1375 is_istreamable<T>::value,
1377 bool lexical_cast(
const std::string &input, T &output) {
1383 template <
typename T,
1384 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1385 !is_istreamable<T>::value && !adl_detail::is_lexical_castable<T>::value,
1388 static_assert(!std::is_same<T, T>::value,
1389 "option object type must have a lexical cast overload or streaming input operator(>>) defined, if it "
1390 "is convertible from another type use the add_option<T, XC>(...) with XC being the known type");
1396 template <
typename AssignTo,
1398 enable_if_t<std::is_same<AssignTo, ConvertTo>::value &&
1399 (classify_object<AssignTo>::value == object_category::string_assignable ||
1400 classify_object<AssignTo>::value == object_category::string_constructible ||
1401 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1402 classify_object<AssignTo>::value == object_category::wstring_constructible),
1409 template <
typename AssignTo,
1412 classify_object<AssignTo>::value != object_category::string_assignable &&
1413 classify_object<AssignTo>::value != object_category::string_constructible &&
1414 classify_object<AssignTo>::value != object_category::wstring_assignable &&
1415 classify_object<AssignTo>::value != object_category::wstring_constructible,
1417 bool lexical_assign(
const std::string &input, AssignTo &output) {
1419 output = AssignTo{};
1427 template <
typename AssignTo,
1429 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1430 classify_object<AssignTo>::value == object_category::wrapper_value,
1432 bool lexical_assign(
const std::string &input, AssignTo &output) {
1434 typename AssignTo::value_type emptyVal{};
1443 template <
typename AssignTo,
1445 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1446 classify_object<AssignTo>::value != object_category::wrapper_value &&
1447 std::is_assignable<AssignTo &, int>::value,
1449 bool lexical_assign(
const std::string &input, AssignTo &output) {
1456 #if defined(__clang__)
1458 #pragma clang diagnostic push
1459 #pragma clang diagnostic ignored "-Wsign-conversion"
1462 #if defined(__clang__)
1463 #pragma clang diagnostic pop
1471 template <
typename AssignTo,
1473 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, ConvertTo &>::value,
1475 bool lexical_assign(
const std::string &input, AssignTo &output) {
1477 bool parse_result = (!input.empty()) ?
lexical_cast(input, val) :
true;
1481 return parse_result;
1488 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, ConvertTo &>::value &&
1489 std::is_move_assignable<AssignTo>::value,
1491 bool lexical_assign(
const std::string &input, AssignTo &output) {
1493 bool parse_result = input.empty() ?
true :
lexical_cast(input, val);
1495 output = AssignTo(val);
1497 return parse_result;
1501 template <
typename AssignTo,
1503 enable_if_t<classify_object<ConvertTo>::value <= object_category::other &&
1504 classify_object<AssignTo>::value <= object_category::wrapper_value,
1506 bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1507 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1512 template <
typename AssignTo,
1514 enable_if_t<(type_count<AssignTo>::value <= 2) && expected_count<AssignTo>::value == 1 &&
1515 is_tuple_like<ConvertTo>::value && type_count_base<ConvertTo>::value == 2,
1517 bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1519 using FirstType =
typename std::remove_const<typename std::tuple_element<0, ConvertTo>::type>::type;
1520 using SecondType =
typename std::tuple_element<1, ConvertTo>::type;
1523 bool retval = lexical_assign<FirstType, FirstType>(strings[0], v1);
1524 retval = retval && lexical_assign<SecondType, SecondType>((strings.size() > 1) ? strings[1] : std::string{}, v2);
1526 output = AssignTo{v1, v2};
1532 template <
class AssignTo,
1534 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1535 type_count<ConvertTo>::value == 1,
1537 bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1538 output.erase(output.begin(), output.end());
1539 if(strings.empty()) {
1542 if(strings.size() == 1 && strings[0] ==
"{}") {
1545 bool skip_remaining =
false;
1546 if(strings.size() == 2 && strings[0] ==
"{}" &&
is_separator(strings[1])) {
1547 skip_remaining =
true;
1549 for(
const auto &elem : strings) {
1550 typename AssignTo::value_type out;
1551 bool retval = lexical_assign<typename AssignTo::value_type, typename ConvertTo::value_type>(elem, out);
1555 output.insert(output.end(), std::move(out));
1556 if(skip_remaining) {
1560 return (!output.empty());
1564 template <class AssignTo, class ConvertTo, enable_if_t<is_complex<ConvertTo>::value, detail::enabler> =
detail::dummy>
1565 bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1567 if(strings.size() >= 2 && !strings[1].empty()) {
1568 using XC2 =
typename wrapped_type<ConvertTo, double>::type;
1570 auto str1 = strings[1];
1571 if(str1.back() ==
'i' || str1.back() ==
'j') {
1576 output = ConvertTo{x, y};
1580 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1584 template <
class AssignTo,
1586 enable_if_t<is_mutable_container<AssignTo>::value && (expected_count<ConvertTo>::value == 1) &&
1587 (type_count<ConvertTo>::value == 1),
1589 bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1592 output.reserve(strings.size());
1593 for(
const auto &elem : strings) {
1595 output.emplace_back();
1596 retval = retval && lexical_assign<typename AssignTo::value_type, ConvertTo>(elem, output.back());
1598 return (!output.empty()) && retval;
1604 template <
class AssignTo,
1606 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1607 type_count_base<ConvertTo>::value == 2,
1609 bool lexical_conversion(std::vector<std::string> strings, AssignTo &output);
1612 template <
class AssignTo,
1614 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1615 type_count_base<ConvertTo>::value != 2 &&
1616 ((type_count<ConvertTo>::value > 2) ||
1617 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1619 bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1622 template <
class AssignTo,
1624 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1625 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1626 type_count<ConvertTo>::value > 2),
1628 bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1632 template <
typename AssignTo,
1634 enable_if_t<!is_tuple_like<AssignTo>::value && !is_mutable_container<AssignTo>::value &&
1635 classify_object<ConvertTo>::value != object_category::wrapper_value &&
1636 (is_mutable_container<ConvertTo>::value || type_count<ConvertTo>::value > 2),
1638 bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1640 if(strings.size() > 1 || (!strings.empty() && !(strings.front().empty()))) {
1642 auto retval = lexical_conversion<ConvertTo, ConvertTo>(strings, val);
1643 output = AssignTo{val};
1646 output = AssignTo{};
1651 template <
class AssignTo,
class ConvertTo, std::
size_t I>
1652 inline typename std::enable_if<(I >= type_count_base<AssignTo>::value),
bool>::type
1653 tuple_conversion(
const std::vector<std::string> &, AssignTo &) {
1658 template <
class AssignTo,
class ConvertTo>
1659 inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && type_count<ConvertTo>::value == 1,
bool>::type
1660 tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1661 auto retval = lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1662 strings.erase(strings.begin());
1667 template <
class AssignTo,
class ConvertTo>
1668 inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && (type_count<ConvertTo>::value > 1) &&
1669 type_count<ConvertTo>::value == type_count_min<ConvertTo>::value,
1671 tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1672 auto retval = lexical_conversion<AssignTo, ConvertTo>(strings, output);
1673 strings.erase(strings.begin(), strings.begin() + type_count<ConvertTo>::value);
1678 template <
class AssignTo,
class ConvertTo>
1679 inline typename std::enable_if<is_mutable_container<ConvertTo>::value ||
1680 type_count<ConvertTo>::value != type_count_min<ConvertTo>::value,
1682 tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1684 std::size_t index{subtype_count_min<ConvertTo>::value};
1685 const std::size_t mx_count{subtype_count<ConvertTo>::value};
1686 const std::size_t mx{(std::min)(mx_count, strings.size() - 1)};
1694 bool retval = lexical_conversion<AssignTo, ConvertTo>(
1695 std::vector<std::string>(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index)), output);
1696 if(strings.size() > index) {
1697 strings.erase(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index) + 1);
1705 template <
class AssignTo,
class ConvertTo, std::
size_t I>
1706 inline typename std::enable_if<(I < type_count_base<AssignTo>::value),
bool>::type
1707 tuple_conversion(std::vector<std::string> strings, AssignTo &output) {
1709 using ConvertToElement =
typename std::
1710 conditional<is_tuple_like<ConvertTo>::value,
typename std::tuple_element<I, ConvertTo>::type, ConvertTo>::type;
1711 if(!strings.empty()) {
1712 retval = retval && tuple_type_conversion<typename std::tuple_element<I, AssignTo>::type, ConvertToElement>(
1713 strings, std::get<I>(output));
1715 retval = retval && tuple_conversion<AssignTo, ConvertTo, I + 1>(std::move(strings), output);
1720 template <
class AssignTo,
1722 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1723 type_count_base<ConvertTo>::value == 2,
1725 bool lexical_conversion(std::vector<std::string> strings, AssignTo &output) {
1727 while(!strings.empty()) {
1729 typename std::remove_const<typename std::tuple_element<0, typename ConvertTo::value_type>::type>::type v1;
1730 typename std::tuple_element<1, typename ConvertTo::value_type>::type v2;
1731 bool retval = tuple_type_conversion<decltype(v1), decltype(v1)>(strings, v1);
1732 if(!strings.empty()) {
1733 retval = retval && tuple_type_conversion<decltype(v2), decltype(v2)>(strings, v2);
1736 output.insert(output.end(),
typename AssignTo::value_type{v1, v2});
1741 return (!output.empty());
1745 template <
class AssignTo,
1747 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1748 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1749 type_count<ConvertTo>::value > 2),
1751 bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1753 !is_tuple_like<ConvertTo>::value || type_count_base<AssignTo>::value == type_count_base<ConvertTo>::value,
1754 "if the conversion type is defined as a tuple it must be the same size as the type you are converting to");
1755 return tuple_conversion<AssignTo, ConvertTo, 0>(strings, output);
1759 template <
class AssignTo,
1761 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1762 type_count_base<ConvertTo>::value != 2 &&
1763 ((type_count<ConvertTo>::value > 2) ||
1764 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1766 bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1769 std::vector<std::string> temp;
1771 std::size_t icount{0};
1772 std::size_t xcm{type_count<ConvertTo>::value};
1773 auto ii_max = strings.size();
1774 while(ii < ii_max) {
1775 temp.push_back(strings[ii]);
1778 if(icount == xcm ||
is_separator(temp.back()) || ii == ii_max) {
1779 if(static_cast<int>(xcm) > type_count_min<ConvertTo>::value &&
is_separator(temp.back())) {
1782 typename AssignTo::value_type temp_out;
1784 lexical_conversion<typename AssignTo::value_type, typename ConvertTo::value_type>(temp, temp_out);
1789 output.insert(output.end(), std::move(temp_out));
1797 template <
typename AssignTo,
1799 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1800 std::is_assignable<ConvertTo &, ConvertTo>::value,
1802 bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1803 if(strings.empty() || strings.front().empty()) {
1804 output = ConvertTo{};
1807 typename ConvertTo::value_type val;
1808 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1809 output = ConvertTo{val};
1816 template <
typename AssignTo,
1818 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1819 !std::is_assignable<AssignTo &, ConvertTo>::value,
1821 bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1822 using ConvertType =
typename ConvertTo::value_type;
1823 if(strings.empty() || strings.front().empty()) {
1824 output = ConvertType{};
1828 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1836 inline std::string sum_string_vector(
const std::vector<std::string> &values) {
1840 for(
const auto &arg : values) {
1846 fail = (errno != 0);
1850 tv =
static_cast<double>(fv);
1855 for(
const auto &arg : values) {
1859 std::ostringstream out;
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
std::string trim_copy(const std::string &str)
Make a copy of the string and then trim it.
Definition: StringTools.hpp:123
void type
Definition: TypeTools.hpp:51
static constexpr bool value
Definition: TypeTools.hpp:204
std::string to_string(T &&value)
Print tuple value string for tuples of size > 1.
Definition: TypeTools.hpp:430
typename std::remove_const< value_type >::type second_type
Definition: TypeTools.hpp:133
Adaptor for set-like structure: This just wraps a normal container in a few utilities that do almost ...
Definition: TypeTools.hpp:130
Definition: TypeTools.hpp:125
static constexpr bool value
Definition: TypeTools.hpp:103
typename T::value_type value_type
Definition: TypeTools.hpp:152
Check for complex.
Definition: TypeTools.hpp:235
A copy of std::void_t from C++17 (helper for C++11 and C++14)
Definition: TypeTools.hpp:50
enabler
Simple empty scoped class.
Definition: TypeTools.hpp:36
Definition: TypeTools.hpp:96
Check to see if something is bool (fail check by default)
Definition: TypeTools.hpp:61
bool is_separator(const std::string &str)
check if a string is a container segment separator (empty or "%%")
Definition: StringTools.hpp:172
typename std::remove_const< value_type >::type first_type
Definition: TypeTools.hpp:132
bool lexical_assign(const std::string &input, AssignTo &output)
Assign a value through lexical cast operations.
Definition: TypeTools.hpp:1404
bool lexical_cast(const std::string &input, T &output)
Integer conversion.
Definition: TypeTools.hpp:1123
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
template to get the underlying value type if it exists or use a default
Definition: TypeTools.hpp:486
def type
Definition: TypeTools.hpp:487
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:337
bool integral_conversion(const std::string &input, T &output) noexcept
Convert to an unsigned integral.
Definition: TypeTools.hpp:946
This can be specialized to override the type deduction for IsMember.
Definition: TypeTools.hpp:81
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
CLI11_MODULE_INLINE constexpr int expected_max_vector_size
Definition: StringTools.hpp:48
Definition: TypeTools.hpp:213
std::string join(const T &v, std::string delim=",")
Simple function to join a string.
Definition: StringTools.hpp:54
This will only trigger for actual void type.
Definition: TypeTools.hpp:311
typename std::remove_const< typename value_type::second_type >::type second_type
Definition: TypeTools.hpp:154
static bool const value
Definition: TypeTools.hpp:77
forward declare the subtype_count_min structure
Definition: TypeTools.hpp:501
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:1071
auto checked_to_string(T &&value) -> decltype(to_string(std::forward< T >(value)))
special template overload
Definition: TypeTools.hpp:456
#define CLI11_MODULE_INLINE
Definition: Macros.hpp:183
Set of overloads to get the type size of an object.
Definition: TypeTools.hpp:498
typename std::enable_if< B, T >::type enable_if_t
Definition: TypeTools.hpp:47
Definition: TypeTools.hpp:260
not a pointer
Definition: TypeTools.hpp:115
std::string to_lower(std::string str)
Return a lower case version of a string.
Definition: StringTools.hpp:182
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
Definition: TypeTools.hpp:291
typename element_type< T >::type::value_type type
Definition: TypeTools.hpp:126
This will only trigger for actual void type.
Definition: TypeTools.hpp:504
constexpr std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size(){return subtype_count< typename std::tuple_element< I, T >::type >::value+tuple_type_size< T, I+1 >);}template< typename T >struct type_count< T, typename std::enable_if< is_tuple_like< T >::value &&!is_complex< T >::value >::type >{static constexpr int value{tuple_type_size< T, 0 >)};};template< typename T > struct subtype_count{static constexpr int value{is_mutable_container< T >::value?expected_max_vector_size:type_count< T >::value};};template< typename T, typename Enable=void > struct type_count_min{static const int value{0};};template< typename T >struct type_count_min< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_tuple_like< T >::value &&!is_wrapper< T >::value &&!is_complex< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{type_count< T >::value};};template< typename T > struct type_count_min< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr int value{1};};template< typename T >struct type_count_min< T, typename std::enable_if< is_wrapper< T >::value &&!is_complex< T >::value &&!is_tuple_like< T >::value >::type >{static constexpr int value{subtype_count_min< typename T::value_type >::value};};template< typename T, std::size_t I >constexpr typename std::enable_if< I==type_count_base< T >::value, int >::type tuple_type_size_min(){return 0;}template< typename T, std::size_t I > constexpr typename std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size_min(){return subtype_count_min< typename std::tuple_element< I, T >::type >::value+tuple_type_size_min< T, I+1 >);}template< typename T >struct type_count_min< T, typename std::enable_if< is_tuple_like< T >::value &&!is_complex< T >::value >::type >{static constexpr int value{tuple_type_size_min< T, 0 >)};};template< typename T > struct subtype_count_min{static constexpr int value{is_mutable_container< T >::value?((type_count< T >::value< expected_max_vector_size)?type_count< T >::value:0):type_count_min< T >::value};};template< typename T, typename Enable=void > struct expected_count{static const int value{0};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_wrapper< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{1};};template< typename T > struct expected_count< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr int value{expected_max_vector_size};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&is_wrapper< T >::value >::type >{static constexpr int value{expected_count< typename T::value_type >::value};};enum class object_category:std::uint8_t{char_value=1, integral_value=2, unsigned_integral=4, enumeration=6, boolean_value=8, floating_point=10, number_constructible=12, double_constructible=14, integer_constructible=16, string_assignable=23, string_constructible=24, wstring_assignable=25, wstring_constructible=26, other=45, wrapper_value=50, complex_number=60, tuple_value=70, container_value=80,};template< typename T, typename Enable=void > struct classify_object{static constexpr object_category value{object_category::other};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&!std::is_same< T, char >::value &&std::is_signed< T >::value &&!is_bool< T >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::integral_value};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&std::is_unsigned< T >::value &&!std::is_same< T, char >::value &&!is_bool< T >::value >::type >{static constexpr object_category value{object_category::unsigned_integral};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_same< T, char >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::char_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_bool< T >::value >::type >{static constexpr object_category value{object_category::boolean_value};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_floating_point< T >::value >::type >{static constexpr object_category value{object_category::floating_point};};#define WIDE_STRING_CHECK#define STRING_CHECKtemplate< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&WIDE_STRING_CHECK &&std::is_assignable< T &, std::string >::value >::type >{static constexpr object_category value{object_category::string_assignable};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&(type_count< T >::value==1)&&WIDE_STRING_CHECK &&std::is_constructible< T, std::string >::value >::type >{static constexpr object_category value{object_category::string_constructible};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&STRING_CHECK &&std::is_assignable< T &, std::wstring >::value >::type >{static constexpr object_category value{object_category::wstring_assignable};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::wstring >::value &&(type_count< T >::value==1)&&STRING_CHECK &&std::is_constructible< T, std::wstring >::value >::type >{static constexpr object_category value{object_category::wstring_constructible};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::enumeration};};template< typename T > struct classify_object< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr object_category value{object_category::complex_number};};template< typename T > struct uncommon_type{using type=typename std::conditional< !std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&!std::is_constructible< T, std::string >::value &&!std::is_assignable< T &, std::wstring >::value &&!std::is_constructible< T, std::wstring >::value &&!is_complex< T >::value &&!is_mutable_container< T >::value &&!std::is_enum< T >::value, std::true_type, std::false_type >::type;static constexpr bool value=type::value;};template< typename T >struct classify_object< T, typename std::enable_if<(!is_mutable_container< T >::value &&is_wrapper< T >::value &&!is_tuple_like< T >::value &&uncommon_type< T >::value)>::type >{static constexpr object_category value{object_category::wrapper_value};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::number_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&!is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::integer_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::double_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< is_tuple_like< T >::value &&((type_count< T >::value >=2 &&!is_wrapper< T >::value)||(uncommon_type< T >::value &&!is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value)||(uncommon_type< T >::value &&type_count< T >::value >=2))>::type >{static constexpr object_category value{object_category::tuple_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr object_category value{object_category::container_value};};template< typename T, enable_if_t< classify_object< T >::value==object_category::char_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"CHAR";}template< typename T, enable_if_t< classify_object< T >::value==object_category::integral_value||classify_object< T >::value==object_category::integer_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"INT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::unsigned_integral, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"UINT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::floating_point||classify_object< T >::value==object_category::number_constructible||classify_object< T >::value==object_category::double_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"FLOAT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::enumeration, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"ENUM";}template< typename T, enable_if_t< classify_object< T >::value==object_category::boolean_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"BOOLEAN";}template< typename T, enable_if_t< classify_object< T >::value==object_category::complex_number, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"COMPLEX";}template< typename T, enable_if_t< classify_object< T >::value >=object_category::string_assignable &&classify_object< T >::value<=object_category::other, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"TEXT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::container_value||classify_object< T >::value==object_category::wrapper_value, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value==1, detail::enabler >=detail::dummy >inline std::string type_name(){return type_name< typename std::decay< typename std::tuple_element< 0, T >::type >::type >);}template< typename T, std::size_t I >inline typename std::enable_if< I==type_count_base< T >::value, std::string >::type tuple_name(){return std::string{};}template< typename T, std::size_t I >inline typename std::enable_if<(I< type_count_base< T >::value), std::string >::type tuple_name(){auto str=std::string{type_name< typename std::decay< typename std::tuple_element< I, T >::type >::type >)}+ ','+tuple_name< T, I+1 >);if(str.back()== ',') str.pop_back();return str;}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler > > std::string type_name()
Recursively generate the tuple type name.
Definition: TypeTools.hpp:927
Check to see if something is a shared pointer.
Definition: TypeTools.hpp:67
CLI11_INLINE std::wstring widen(const std::string &str)
Convert a narrow string to a wide string.
typename std::pointer_traits< T >::element_type type
Definition: TypeTools.hpp:120
constexpr std::enable_if< I==type_count_base< T >::value, int >::type tuple_type_size()
0 if the index > tuple size
Definition: TypeTools.hpp:536
CLI11_INLINE std::string get_group_separators()
get valid group separators _' + local separator if different
std::string value_string(const T &value)
get a string as a convertible value for arithmetic types
Definition: TypeTools.hpp:470
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
Definition: TypeTools.hpp:299
T type
Definition: TypeTools.hpp:82
CLI11_MODULE_INLINE constexpr enabler dummy
An instance to use in EnableIf.
Definition: TypeTools.hpp:39
std::enable_if< I==type_count_base< T >::value, std::string >::type tuple_value_string(T &&)
Convert a tuple like object to a string.
Definition: TypeTools.hpp:438
typename T::value_type type
Definition: TypeTools.hpp:492
bool from_stream(const std::string &istring, T &obj)
Templated operation to get a value from a stream.
Definition: TypeTools.hpp:247
Check to see if something is copyable pointer.
Definition: TypeTools.hpp:76
Check for input streamability.
Definition: TypeTools.hpp:224
Definition: TypeTools.hpp:177
typename std::remove_const< typename value_type::first_type >::type first_type
Definition: TypeTools.hpp:153
typename T::value_type value_type
Definition: TypeTools.hpp:131
Definition: TypeTools.hpp:280
std::string type
Definition: TypeTools.hpp:87
T type
Definition: TypeTools.hpp:116
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