27#include "Encoding.hpp"
28#include "StringTools.hpp"
39enum class enabler : std::uint8_t {};
42CLI11_MODULE_INLINE
constexpr enabler dummy = {};
50template <
bool B,
class T =
void>
using enable_if_t =
typename std::enable_if<B, T>::type;
58template <
typename... Ts>
using void_t =
typename make_void<Ts...>::type;
61template <
bool B,
class T,
class F>
using conditional_t =
typename std::conditional<B, T, F>::type;
64template <
typename T>
struct is_bool : std::false_type {};
67template <>
struct is_bool<bool> : std::true_type {};
73template <
typename T>
struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
76template <
typename T>
struct is_shared_ptr<const std::shared_ptr<T>> : std::true_type {};
90 using type = std::string;
100 template <
typename TT,
typename SS>
101 static auto test(
int) ->
decltype(lexical_cast(std::declval<const SS &>(), std::declval<TT &>()), std::true_type());
103 template <
typename,
typename>
static auto test(...) -> std::false_type;
106 static constexpr bool value =
decltype(test<T, S>(0))::value;
122template <
typename T>
struct element_type<T, typename std::enable_if<is_copyable_ptr<T>::value>::type> {
123 using type =
typename std::pointer_traits<T>::element_type;
133template <
typename T,
typename _ =
void>
struct pair_adaptor : std::false_type {
134 using value_type =
typename T::value_type;
135 using first_type =
typename std::remove_const<value_type>::type;
136 using second_type =
typename std::remove_const<value_type>::type;
139 template <
typename Q>
static auto first(Q &&pair_value) ->
decltype(std::forward<Q>(pair_value)) {
140 return std::forward<Q>(pair_value);
143 template <
typename Q>
static auto second(Q &&pair_value) ->
decltype(std::forward<Q>(pair_value)) {
144 return std::forward<Q>(pair_value);
153 conditional_t<false, void_t<typename T::value_type::first_type, typename T::value_type::second_type>, void>>
155 using value_type =
typename T::value_type;
156 using first_type =
typename std::remove_const<typename value_type::first_type>::type;
157 using second_type =
typename std::remove_const<typename value_type::second_type>::type;
160 template <
typename Q>
static auto first(Q &&pair_value) ->
decltype(std::get<0>(std::forward<Q>(pair_value))) {
161 return std::get<0>(std::forward<Q>(pair_value));
164 template <
typename Q>
static auto second(Q &&pair_value) ->
decltype(std::get<1>(std::forward<Q>(pair_value))) {
165 return std::get<1>(std::forward<Q>(pair_value));
176#pragma GCC diagnostic push
177#pragma GCC diagnostic ignored "-Wnarrowing"
181 template <
typename TT,
typename CC>
182 static auto test(
int, std::true_type) ->
decltype(
185#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
186#pragma nv_diag_suppress 2361
188#pragma diag_suppress 2361
191 TT{std::declval<CC>()}
193#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
194#pragma nv_diag_default 2361
196#pragma diag_default 2361
200 std::is_move_assignable<TT>());
202 template <
typename TT,
typename CC>
static auto test(
int, std::false_type) -> std::false_type;
204 template <
typename,
typename>
static auto test(...) -> std::false_type;
207 static constexpr bool value =
decltype(test<T, C>(0,
typename std::is_constructible<T, C>::type()))::value;
210#pragma GCC diagnostic pop
217 template <
typename TT,
typename SS>
218 static auto test(
int) ->
decltype(std::declval<SS &>() << std::declval<TT>(), std::true_type());
220 template <
typename,
typename>
static auto test(...) -> std::false_type;
223 static constexpr bool value =
decltype(test<T, S>(0))::value;
228 template <
typename TT,
typename SS>
229 static auto test(
int) ->
decltype(std::declval<SS &>() >> std::declval<TT &>(), std::true_type());
231 template <
typename,
typename>
static auto test(...) -> std::false_type;
234 static constexpr bool value =
decltype(test<T, S>(0))::value;
239 template <
typename TT>
240 static auto test(
int) ->
decltype(std::declval<TT>().real(), std::declval<TT>().imag(), std::true_type());
242 template <
typename>
static auto test(...) -> std::false_type;
245 static constexpr bool value =
decltype(test<T>(0))::value;
249template <typename T, enable_if_t<is_istreamable<T>::value, detail::enabler> = detail::dummy>
250bool from_stream(
const std::string &istring, T &obj) {
251 std::istringstream is;
254 return !is.fail() && !is.rdbuf()->in_avail();
257template <typename T, enable_if_t<!is_istreamable<T>::value, detail::enabler> = detail::dummy>
258bool from_stream(
const std::string & , T & ) {
272 void_t<typename T::value_type,
273 decltype(std::declval<T>().end()),
274 decltype(std::declval<T>().clear()),
275 decltype(std::declval<T>().insert(std::declval<decltype(std::declval<T>().end())>(),
276 std::declval<const typename T::value_type &>()))>,
277 void>> :
public conditional_t<std::is_constructible<T, std::string>::value ||
278 std::is_constructible<T, std::wstring>::value,
290 conditional_t<false, void_t<decltype(std::declval<T>().end()), decltype(std::declval<T>().begin())>, void>>
291 :
public std::true_type {};
294template <
typename T,
typename _ =
void>
struct is_wrapper : std::false_type {};
298struct is_wrapper<T, conditional_t<false, void_t<typename T::value_type>, void>> :
public std::true_type {};
303 template <typename SS, enable_if_t<!is_complex<SS>::value, detail::enabler> = detail::dummy>
306 static auto test(
int) ->
decltype(std::tuple_size<typename std::decay<SS>::type>::value, std::true_type{});
307 template <
typename>
static auto test(...) -> std::false_type;
310 static constexpr bool value =
decltype(test<S>(0))::value;
315 static const int value{0};
321 typename std::enable_if<!is_tuple_like<T>::value && !is_mutable_container<T>::value &&
322 !std::is_void<T>::value>::type> {
323 static constexpr int value{1};
328struct type_count_base<T, typename std::enable_if<is_tuple_like<T>::value && !is_mutable_container<T>::value>::type> {
329 static constexpr int value{
330 std::tuple_size<typename std::decay<T>::type>::value};
334template <
typename T>
struct type_count_base<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
335 static constexpr int value{type_count_base<typename T::value_type>::value};
339template <typename T, enable_if_t<std::is_convertible<T, std::string>::value, detail::enabler> = detail::dummy>
340auto to_string(T &&value) ->
decltype(std::forward<T>(value)) {
341 return std::forward<T>(value);
346 enable_if_t<std::is_constructible<std::string, T>::value && !std::is_convertible<T, std::string>::value,
347 detail::enabler> = detail::dummy>
348std::string to_string(T &&value) {
349 return std::string(value);
354 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
355 is_ostreamable<T>::value,
356 detail::enabler> = detail::dummy>
357std::string to_string(T &&value) {
358 std::stringstream stream;
367 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
368 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value == 1,
369 detail::enabler> = detail::dummy>
370inline std::string to_string(T &&value);
374 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
375 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value >= 2,
376 detail::enabler> = detail::dummy>
377inline std::string to_string(T &&value);
382 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
384 !is_tuple_like<T>::value,
385 detail::enabler> = detail::dummy>
386inline std::string to_string(T &&) {
392 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
394 detail::enabler> = detail::dummy>
395inline std::string to_string(T &&variable) {
396 auto cval = variable.begin();
397 auto end = variable.end();
401 std::vector<std::string> defaults;
403 defaults.emplace_back(CLI::detail::to_string(*cval));
406 return {
"[" + detail::join(defaults) +
"]"};
412template <
typename T, std::
size_t I>
413inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_value_string(T && );
416template <
typename T, std::
size_t I>
417inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_value_string(T &&value);
421 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
422 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value == 1,
424inline std::string to_string(T &&value) {
425 return to_string(std::get<0>(value));
430 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
431 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value >= 2,
433inline std::string to_string(T &&value) {
434 auto tname = std::string(1,
'[') + tuple_value_string<T, 0>(value);
435 tname.push_back(
']');
440template <
typename T, std::
size_t I>
441inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_value_string(T && ) {
442 return std::string{};
446template <
typename T, std::
size_t I>
447inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_value_string(T &&value) {
448 auto str = std::string{to_string(std::get<I>(value))} +
',' + tuple_value_string<T, I + 1>(value);
449 if(str.back() ==
',')
455template <
typename T1,
458 enable_if_t<std::is_same<T1, T2>::value, detail::enabler> = detail::dummy>
459auto checked_to_string(T &&value) ->
decltype(to_string(std::forward<T>(value))) {
460 return to_string(std::forward<T>(value));
464template <
typename T1,
467 enable_if_t<!std::is_same<T1, T2>::value, detail::enabler> = detail::dummy>
468std::string checked_to_string(T &&) {
469 return std::string{};
472template <typename T, enable_if_t<std::is_arithmetic<T>::value, detail::enabler> = detail::dummy>
473std::string value_string(
const T &value) {
474 return std::to_string(value);
477template <typename T, enable_if_t<std::is_enum<T>::value, detail::enabler> = detail::dummy>
478std::string value_string(
const T &value) {
479 return std::to_string(
static_cast<typename std::underlying_type<T>::type
>(value));
483 enable_if_t<!std::is_enum<T>::value && !std::is_arithmetic<T>::value, detail::enabler> = detail::dummy>
484auto value_string(
const T &value) ->
decltype(to_string(value)) {
485 return to_string(value);
489template <
typename T,
typename def,
typename Enable =
void>
struct wrapped_type {
494template <
typename T,
typename def>
struct wrapped_type<T, def, typename std::enable_if<is_wrapper<T>::value>::type> {
495 using type =
typename T::value_type;
507template <
typename T,
typename Enable =
void>
struct type_count {
508 static const int value{0};
514 typename std::enable_if<!is_wrapper<T>::value && !is_tuple_like<T>::value && !is_complex<T>::value &&
515 !std::is_void<T>::value>::type> {
516 static constexpr int value{1};
520template <
typename T>
struct type_count<T, typename std::enable_if<is_complex<T>::value>::type> {
521 static constexpr int value{2};
525template <
typename T>
struct type_count<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
532 typename std::enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value &&
533 !is_mutable_container<T>::value>::type> {
534 static constexpr int value{type_count<typename T::value_type>::value};
538template <
typename T, std::
size_t I>
539constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type tuple_type_size() {
544template <
typename T, std::
size_t I>
545 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type tuple_type_size() {
546 return subtype_count<typename std::tuple_element<I, T>::type>::value + tuple_type_size<T, I + 1>();
551struct type_count<T, typename std::enable_if<is_tuple_like<T>::value && !is_complex<T>::value>::type> {
552 static constexpr int value{tuple_type_size<T, 0>()};
557 static constexpr int value{is_mutable_container<T>::value ? expected_max_vector_size : type_count<T>::value};
561template <
typename T,
typename Enable =
void>
struct type_count_min {
562 static const int value{0};
567struct type_count_min<
569 typename std::enable_if<!is_mutable_container<T>::value && !is_tuple_like<T>::value && !is_wrapper<T>::value &&
570 !is_complex<T>::value && !std::is_void<T>::value>::type> {
571 static constexpr int value{type_count<T>::value};
575template <
typename T>
struct type_count_min<T, typename std::enable_if<is_complex<T>::value>::type> {
576 static constexpr int value{1};
581struct type_count_min<
583 typename std::enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value>::type> {
584 static constexpr int value{subtype_count_min<typename T::value_type>::value};
588template <
typename T, std::
size_t I>
589constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type tuple_type_size_min() {
594template <
typename T, std::
size_t I>
595 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type tuple_type_size_min() {
601struct type_count_min<T, typename std::enable_if<is_tuple_like<T>::value && !is_complex<T>::value>::type> {
602 static constexpr int value{tuple_type_size_min<T, 0>()};
607 static constexpr int value{is_mutable_container<T>::value
608 ? ((type_count<T>::value < expected_max_vector_size) ? type_count<T>::value : 0)
609 : type_count_min<T>::value};
613template <
typename T,
typename Enable =
void>
struct expected_count {
614 static const int value{0};
619struct expected_count<T,
620 typename std::enable_if<!is_mutable_container<T>::value && !is_wrapper<T>::value &&
621 !std::is_void<T>::value>::type> {
622 static constexpr int value{1};
625template <
typename T>
struct expected_count<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
626 static constexpr int value{expected_max_vector_size};
631struct expected_count<T, typename std::enable_if<!is_mutable_container<T>::value && is_wrapper<T>::value>::type> {
632 static constexpr int value{expected_count<typename T::value_type>::value};
636enum class object_category : std::uint8_t {
639 unsigned_integral = 4,
643 number_constructible = 12,
644 double_constructible = 14,
645 integer_constructible = 16,
647 string_assignable = 23,
648 string_constructible = 24,
649 wstring_assignable = 25,
650 wstring_constructible = 26,
656 container_value = 80,
663template <
typename T,
typename Enable =
void>
struct classify_object {
664 static constexpr object_category value{object_category::other};
669struct classify_object<
671 typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, char>::value && std::is_signed<T>::value &&
672 !is_bool<T>::value && !std::is_enum<T>::value>::type> {
673 static constexpr object_category value{object_category::integral_value};
678struct classify_object<T,
679 typename std::enable_if<std::is_integral<T>::value && std::is_unsigned<T>::value &&
680 !std::is_same<T, char>::value && !is_bool<T>::value>::type> {
681 static constexpr object_category value{object_category::unsigned_integral};
686struct classify_object<T, typename std::enable_if<std::is_same<T, char>::value && !std::is_enum<T>::value>::type> {
687 static constexpr object_category value{object_category::char_value};
691template <
typename T>
struct classify_object<T, typename std::enable_if<is_bool<T>::value>::type> {
692 static constexpr object_category value{object_category::boolean_value};
696template <
typename T>
struct classify_object<T, typename std::enable_if<std::is_floating_point<T>::value>::type> {
697 static constexpr object_category value{object_category::floating_point};
702#define WIDE_STRING_CHECK \
703 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value
704#define STRING_CHECK true
706#define WIDE_STRING_CHECK true
707#define STRING_CHECK !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value
712struct classify_object<
714 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value && WIDE_STRING_CHECK &&
715 std::is_assignable<T &, std::string>::value>::type> {
716 static constexpr object_category value{object_category::string_assignable};
721struct classify_object<
723 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
724 !std::is_assignable<T &, std::string>::value && (type_count<T>::value == 1) &&
725 WIDE_STRING_CHECK && std::is_constructible<T, std::string>::value>::type> {
726 static constexpr object_category value{object_category::string_constructible};
731struct classify_object<T,
732 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
733 STRING_CHECK && std::is_assignable<T &, std::wstring>::value>::type> {
734 static constexpr object_category value{object_category::wstring_assignable};
738struct classify_object<
740 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
741 !std::is_assignable<T &, std::wstring>::value && (type_count<T>::value == 1) &&
742 STRING_CHECK && std::is_constructible<T, std::wstring>::value>::type> {
743 static constexpr object_category value{object_category::wstring_constructible};
747template <
typename T>
struct classify_object<T, typename std::enable_if<std::is_enum<T>::value>::type> {
748 static constexpr object_category value{object_category::enumeration};
751template <
typename T>
struct classify_object<T, typename std::enable_if<is_complex<T>::value>::type> {
752 static constexpr object_category value{object_category::complex_number};
757template <
typename T>
struct uncommon_type {
758 using type =
typename std::conditional<
759 !std::is_floating_point<T>::value && !std::is_integral<T>::value &&
760 !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value &&
761 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value &&
762 !is_complex<T>::value && !is_mutable_container<T>::value && !std::is_enum<T>::value,
764 std::false_type>::type;
765 static constexpr bool value = type::value;
770struct classify_object<T,
771 typename std::enable_if<(!is_mutable_container<T>::value && is_wrapper<T>::value &&
772 !is_tuple_like<T>::value && uncommon_type<T>::value)>::type> {
773 static constexpr object_category value{object_category::wrapper_value};
778struct classify_object<T,
779 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
780 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
781 is_direct_constructible<T, int>::value>::type> {
782 static constexpr object_category value{object_category::number_constructible};
787struct classify_object<T,
788 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
789 !is_wrapper<T>::value && !is_direct_constructible<T, double>::value &&
790 is_direct_constructible<T, int>::value>::type> {
791 static constexpr object_category value{object_category::integer_constructible};
796struct classify_object<T,
797 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
798 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
799 !is_direct_constructible<T, int>::value>::type> {
800 static constexpr object_category value{object_category::double_constructible};
805struct classify_object<
807 typename std::enable_if<is_tuple_like<T>::value &&
808 ((type_count<T>::value >= 2 && !is_wrapper<T>::value) ||
809 (uncommon_type<T>::value && !is_direct_constructible<T, double>::value &&
810 !is_direct_constructible<T, int>::value) ||
811 (uncommon_type<T>::value && type_count<T>::value >= 2))>::type> {
812 static constexpr object_category value{object_category::tuple_value};
821template <
typename T>
struct classify_object<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
822 static constexpr object_category value{object_category::container_value};
832 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> = detail::dummy>
833constexpr const char *type_name() {
838 enable_if_t<classify_object<T>::value == object_category::integral_value ||
839 classify_object<T>::value == object_category::integer_constructible,
840 detail::enabler> = detail::dummy>
841constexpr const char *type_name() {
846 enable_if_t<classify_object<T>::value == object_category::unsigned_integral, detail::enabler> = detail::dummy>
847constexpr const char *type_name() {
852 enable_if_t<classify_object<T>::value == object_category::floating_point ||
853 classify_object<T>::value == object_category::number_constructible ||
854 classify_object<T>::value == object_category::double_constructible,
855 detail::enabler> = detail::dummy>
856constexpr const char *type_name() {
862 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
863constexpr const char *type_name() {
869 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
870constexpr const char *type_name() {
876 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
877constexpr const char *type_name() {
883 enable_if_t<classify_object<T>::value >= object_category::string_assignable &&
884 classify_object<T>::value <= object_category::other,
885 detail::enabler> = detail::dummy>
886constexpr const char *type_name() {
891 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value >= 2,
892 detail::enabler> = detail::dummy>
893std::string type_name();
897 enable_if_t<classify_object<T>::value == object_category::container_value ||
898 classify_object<T>::value == object_category::wrapper_value,
899 detail::enabler> = detail::dummy>
900std::string type_name();
904 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value == 1,
905 detail::enabler> = detail::dummy>
906inline std::string type_name() {
907 return type_name<typename std::decay<typename std::tuple_element<0, T>::type>::type>();
911template <
typename T, std::
size_t I>
912inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_name() {
913 return std::string{};
917template <
typename T, std::
size_t I>
918inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_name() {
919 auto str = std::string{type_name<typename std::decay<typename std::tuple_element<I, T>::type>::type>()} +
',' +
920 tuple_name<T, I + 1>();
921 if(str.back() ==
',')
928 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value >= 2,
930inline std::string type_name() {
931 auto tname = std::string(1,
'[') + tuple_name<T, 0>();
932 tname.push_back(
']');
938 enable_if_t<classify_object<T>::value == object_category::container_value ||
939 classify_object<T>::value == object_category::wrapper_value,
941inline std::string type_name() {
942 return type_name<typename T::value_type>();
948template <typename T, enable_if_t<std::is_unsigned<T>::value, detail::enabler> = detail::dummy>
949bool integral_conversion(
const std::string &input, T &output)
noexcept {
955 auto first_non_ws = input.find_first_not_of(
" \t\n\v\f\r");
956 if(first_non_ws != std::string::npos && input[first_non_ws] ==
'-') {
961 std::uint64_t output_ll = std::strtoull(input.c_str(), &val, 0);
962 if(errno == ERANGE) {
965 output =
static_cast<T
>(output_ll);
966 if(val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll) {
970 std::int64_t output_sll = std::strtoll(input.c_str(), &val, 0);
971 if(val == (input.c_str() + input.size())) {
972 output = (output_sll < 0) ? static_cast<T>(0) : static_cast<T>(output_sll);
973 return (
static_cast<std::int64_t
>(output) == output_sll);
976 auto group_separators = get_group_separators();
977 if(input.find_first_of(group_separators) != std::string::npos) {
978 std::string nstring = input;
979 for(
auto &separator : group_separators) {
980 if(input.find_first_of(separator) != std::string::npos) {
981 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
984 return integral_conversion(nstring, output);
987 if(std::isspace(
static_cast<unsigned char>(input.back()))) {
988 return integral_conversion(trim_copy(input), output);
990 if(input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0) {
993 output_ll = std::strtoull(input.c_str() + 2, &val, 8);
994 if(errno == ERANGE) {
997 output =
static_cast<T
>(output_ll);
998 return (val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll);
1000 if(input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0) {
1006 output_ll = std::strtoull(input.c_str() + 2, &val, 2);
1007 if(errno == ERANGE) {
1010 output =
static_cast<T
>(output_ll);
1011 return (val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll);
1018template <typename T, enable_if_t<std::is_signed<T>::value, detail::enabler> = detail::dummy>
1019bool integral_conversion(
const std::string &input, T &output)
noexcept {
1023 char *val =
nullptr;
1025 std::int64_t output_ll = std::strtoll(input.c_str(), &val, 0);
1026 if(errno == ERANGE) {
1029 output =
static_cast<T
>(output_ll);
1030 if(val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll) {
1033 if(input ==
"true") {
1035 output =
static_cast<T
>(1);
1039 auto group_separators = get_group_separators();
1040 if(input.find_first_of(group_separators) != std::string::npos) {
1041 for(
auto &separator : group_separators) {
1042 if(input.find_first_of(separator) != std::string::npos) {
1043 std::string nstring = input;
1044 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1045 return integral_conversion(nstring, output);
1049 if(std::isspace(
static_cast<unsigned char>(input.back()))) {
1050 return integral_conversion(trim_copy(input), output);
1052 if(input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0) {
1055 output_ll = std::strtoll(input.c_str() + 2, &val, 8);
1056 if(errno == ERANGE) {
1059 output =
static_cast<T
>(output_ll);
1060 return (val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll);
1062 if(input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0) {
1068 output_ll = std::strtoll(input.c_str() + 2, &val, 2);
1069 if(errno == ERANGE) {
1072 output =
static_cast<T
>(output_ll);
1073 return (val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll);
1080inline std::int64_t to_flag_value(std::string val)
noexcept {
1081 static const std::string trueString(
"true");
1082 static const std::string falseString(
"false");
1083 if(val == trueString) {
1086 if(val == falseString) {
1089 val = detail::to_lower(std::move(val));
1090 std::int64_t ret = 0;
1091 if(val.size() == 1) {
1092 if(val[0] >=
'1' && val[0] <=
'9') {
1093 return (
static_cast<std::int64_t
>(val[0]) -
'0');
1113 if(val == trueString || val ==
"on" || val ==
"yes" || val ==
"enable") {
1115 }
else if(val == falseString || val ==
"off" || val ==
"no" || val ==
"disable") {
1118 char *loc_ptr{
nullptr};
1119 ret = std::strtoll(val.c_str(), &loc_ptr, 0);
1120 if(loc_ptr != (val.c_str() + val.size()) && errno == 0) {
1128template <
typename T,
1129 enable_if_t<classify_object<T>::value == object_category::integral_value ||
1130 classify_object<T>::value == object_category::unsigned_integral,
1131 detail::enabler> = detail::dummy>
1132bool lexical_cast(
const std::string &input, T &output) {
1133 return integral_conversion(input, output);
1137template <
typename T,
1138 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> = detail::dummy>
1139bool lexical_cast(
const std::string &input, T &output) {
1140 if(input.size() == 1) {
1141 output =
static_cast<T
>(input[0]);
1147 bool result = integral_conversion(input, res);
1149 output =
static_cast<T
>(res);
1155template <
typename T,
1156 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
1157bool lexical_cast(
const std::string &input, T &output) {
1159 auto out = to_flag_value(input);
1162 }
else if(errno == ERANGE) {
1163 output = (input[0] !=
'-');
1171template <
typename T,
1172 enable_if_t<classify_object<T>::value == object_category::floating_point, detail::enabler> = detail::dummy>
1173bool lexical_cast(
const std::string &input, T &output) {
1177 char *val =
nullptr;
1178 auto output_ld = std::strtold(input.c_str(), &val);
1181 if(val == input.c_str()) {
1184 output =
static_cast<T
>(output_ld);
1185 if(val == (input.c_str() + input.size())) {
1188 while(std::isspace(
static_cast<unsigned char>(*val))) {
1190 if(val == (input.c_str() + input.size())) {
1196 auto group_separators = get_group_separators();
1197 if(input.find_first_of(group_separators) != std::string::npos) {
1198 for(
auto &separator : group_separators) {
1199 if(input.find_first_of(separator) != std::string::npos) {
1200 std::string nstring = input;
1201 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1202 return lexical_cast(nstring, output);
1210template <
typename T,
1211 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
1212bool lexical_cast(
const std::string &input, T &output) {
1213 using XC =
typename wrapped_type<T, double>::type;
1216 bool worked =
false;
1217 auto nloc = str1.find_last_of(
"+-");
1218 if(nloc != std::string::npos && nloc > 0) {
1219 worked = lexical_cast(str1.substr(0, nloc), x);
1220 str1 = str1.substr(nloc);
1221 if(str1.back() ==
'i' || str1.back() ==
'j')
1223 worked = worked && lexical_cast(str1, y);
1225 if(str1.back() ==
'i' || str1.back() ==
'j') {
1227 worked = lexical_cast(str1, y);
1230 worked = lexical_cast(str1, x);
1238 return from_stream(input, output);
1242template <
typename T,
1243 enable_if_t<classify_object<T>::value == object_category::string_assignable, detail::enabler> = detail::dummy>
1244bool lexical_cast(
const std::string &input, T &output) {
1252 enable_if_t<classify_object<T>::value == object_category::string_constructible, detail::enabler> = detail::dummy>
1253bool lexical_cast(
const std::string &input, T &output) {
1261 enable_if_t<classify_object<T>::value == object_category::wstring_assignable, detail::enabler> = detail::dummy>
1262bool lexical_cast(
const std::string &input, T &output) {
1263 output = widen(input);
1269 enable_if_t<classify_object<T>::value == object_category::wstring_constructible, detail::enabler> = detail::dummy>
1270bool lexical_cast(
const std::string &input, T &output) {
1271 output = T{widen(input)};
1276template <
typename T,
1277 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
1278bool lexical_cast(
const std::string &input, T &output) {
1279 typename std::underlying_type<T>::type val;
1280 if(!integral_conversion(input, val)) {
1283 output =
static_cast<T
>(val);
1288template <
typename T,
1289 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1290 std::is_assignable<T &, typename T::value_type>::value,
1291 detail::enabler> = detail::dummy>
1292bool lexical_cast(
const std::string &input, T &output) {
1293 typename T::value_type val;
1294 if(lexical_cast(input, val)) {
1298 return from_stream(input, output);
1301template <
typename T,
1302 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1303 !std::is_assignable<T &, typename T::value_type>::value && std::is_assignable<T &, T>::value,
1304 detail::enabler> = detail::dummy>
1305bool lexical_cast(
const std::string &input, T &output) {
1306 typename T::value_type val;
1307 if(lexical_cast(input, val)) {
1311 return from_stream(input, output);
1317 enable_if_t<classify_object<T>::value == object_category::number_constructible, detail::enabler> = detail::dummy>
1318bool lexical_cast(
const std::string &input, T &output) {
1320 if(integral_conversion(input, val)) {
1326 if(lexical_cast(input, dval)) {
1331 return from_stream(input, output);
1337 enable_if_t<classify_object<T>::value == object_category::integer_constructible, detail::enabler> = detail::dummy>
1338bool lexical_cast(
const std::string &input, T &output) {
1340 if(integral_conversion(input, val)) {
1344 return from_stream(input, output);
1350 enable_if_t<classify_object<T>::value == object_category::double_constructible, detail::enabler> = detail::dummy>
1351bool lexical_cast(
const std::string &input, T &output) {
1353 if(lexical_cast(input, val)) {
1357 return from_stream(input, output);
1361template <
typename T,
1362 enable_if_t<classify_object<T>::value == object_category::other && std::is_assignable<T &, int>::value,
1363 detail::enabler> = detail::dummy>
1364bool lexical_cast(
const std::string &input, T &output) {
1366 if(integral_conversion(input, val)) {
1368#pragma warning(push)
1369#pragma warning(disable : 4800)
1382 return from_stream(input, output);
1387template <
typename T,
1388 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1389 is_istreamable<T>::value,
1390 detail::enabler> = detail::dummy>
1391bool lexical_cast(
const std::string &input, T &output) {
1392 return from_stream(input, output);
1397template <
typename T,
1398 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1399 !is_istreamable<T>::value && !adl_detail::is_lexical_castable<T>::value,
1400 detail::enabler> = detail::dummy>
1401bool lexical_cast(
const std::string & , T & ) {
1402 static_assert(!std::is_same<T, T>::value,
1403 "option object type must have a lexical cast overload or streaming input operator(>>) defined, if it "
1404 "is convertible from another type use the add_option<T, XC>(...) with XC being the known type");
1410template <
typename AssignTo,
1412 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !is_wrapper<AssignTo>::value &&
1413 (classify_object<AssignTo>::value == object_category::string_assignable ||
1414 classify_object<AssignTo>::value == object_category::string_constructible ||
1415 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1416 classify_object<AssignTo>::value == object_category::wstring_constructible),
1417 detail::enabler> = detail::dummy>
1418bool lexical_assign(
const std::string &input, AssignTo &output) {
1419 return lexical_cast(input, output);
1424template <
typename AssignTo,
1426 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && is_wrapper<AssignTo>::value &&
1427 (classify_object<AssignTo>::value == object_category::string_assignable ||
1428 classify_object<AssignTo>::value == object_category::string_constructible ||
1429 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1430 classify_object<AssignTo>::value == object_category::wstring_constructible),
1431 detail::enabler> = detail::dummy>
1432bool lexical_assign(
const std::string &input, AssignTo &output) {
1434 output = AssignTo{};
1437 return lexical_cast(input, output);
1441template <
typename AssignTo,
1443 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, AssignTo>::value &&
1444 classify_object<AssignTo>::value != object_category::string_assignable &&
1445 classify_object<AssignTo>::value != object_category::string_constructible &&
1446 classify_object<AssignTo>::value != object_category::wstring_assignable &&
1447 classify_object<AssignTo>::value != object_category::wstring_constructible,
1448 detail::enabler> = detail::dummy>
1449bool lexical_assign(
const std::string &input, AssignTo &output) {
1451 output = AssignTo{};
1455 return lexical_cast(input, output);
1459template <
typename AssignTo,
1461 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1462 classify_object<AssignTo>::value == object_category::wrapper_value,
1463 detail::enabler> = detail::dummy>
1464bool lexical_assign(
const std::string &input, AssignTo &output) {
1466 typename AssignTo::value_type emptyVal{};
1470 return lexical_cast(input, output);
1475template <
typename AssignTo,
1477 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1478 classify_object<AssignTo>::value != object_category::wrapper_value &&
1479 std::is_assignable<AssignTo &, int>::value,
1480 detail::enabler> = detail::dummy>
1481bool lexical_assign(
const std::string &input, AssignTo &output) {
1487 if(lexical_cast(input, val)) {
1488#if defined(__clang__)
1490#pragma clang diagnostic push
1491#pragma clang diagnostic ignored "-Wsign-conversion"
1492#elif defined(__GNUC__) && (__GNUC__ == 8)
1494#pragma GCC diagnostic push
1495#pragma GCC diagnostic ignored "-Wsign-conversion"
1498#if defined(__clang__)
1499#pragma clang diagnostic pop
1500#elif defined(__GNUC__) && (__GNUC__ == 8)
1501#pragma GCC diagnostic pop
1509template <
typename AssignTo,
1511 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, ConvertTo &>::value,
1512 detail::enabler> = detail::dummy>
1513bool lexical_assign(
const std::string &input, AssignTo &output) {
1515 bool parse_result = (!input.empty()) ? lexical_cast(input, val) : true;
1519 return parse_result;
1526 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, ConvertTo &>::value &&
1527 std::is_move_assignable<AssignTo>::value,
1528 detail::enabler> = detail::dummy>
1529bool lexical_assign(
const std::string &input, AssignTo &output) {
1531 bool parse_result = input.empty() ? true : lexical_cast(input, val);
1533 output = AssignTo(val);
1535 return parse_result;
1539template <
typename AssignTo,
1541 enable_if_t<classify_object<ConvertTo>::value <= object_category::other &&
1542 classify_object<AssignTo>::value <= object_category::wrapper_value,
1543 detail::enabler> = detail::dummy>
1544bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1545 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1550template <
typename AssignTo,
1552 enable_if_t<(type_count<AssignTo>::value <= 2) && expected_count<AssignTo>::value == 1 &&
1553 is_tuple_like<ConvertTo>::value && type_count_base<ConvertTo>::value == 2,
1554 detail::enabler> = detail::dummy>
1555bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1557 using FirstType =
typename std::remove_const<typename std::tuple_element<0, ConvertTo>::type>::type;
1558 using SecondType =
typename std::tuple_element<1, ConvertTo>::type;
1561 bool retval = lexical_assign<FirstType, FirstType>(strings[0], v1);
1562 retval = retval && lexical_assign<SecondType, SecondType>((strings.size() > 1) ? strings[1] : std::string{}, v2);
1564 output = AssignTo{v1, v2};
1570template <
class AssignTo,
1572 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1573 type_count<ConvertTo>::value == 1,
1574 detail::enabler> = detail::dummy>
1575bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1576 output.erase(output.begin(), output.end());
1577 if(strings.empty()) {
1580 if(strings.size() == 1 && strings[0] ==
"{}") {
1583 bool skip_remaining =
false;
1584 if(strings.size() == 2 && strings[0] ==
"{}" && is_separator(strings[1])) {
1585 skip_remaining =
true;
1587 for(
const auto &elem : strings) {
1588 typename AssignTo::value_type out;
1589 bool retval = lexical_assign<typename AssignTo::value_type, typename ConvertTo::value_type>(elem, out);
1593 output.insert(output.end(), std::move(out));
1594 if(skip_remaining) {
1598 return (!output.empty());
1602template <class AssignTo, class ConvertTo, enable_if_t<is_complex<ConvertTo>::value, detail::enabler> = detail::dummy>
1603bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1605 if(strings.size() >= 2 && !strings[1].empty()) {
1606 using XC2 =
typename wrapped_type<ConvertTo, double>::type;
1608 auto str1 = strings[1];
1609 if(str1.back() ==
'i' || str1.back() ==
'j') {
1612 auto worked = lexical_cast(strings[0], x) && lexical_cast(str1, y);
1614 output = ConvertTo{x, y};
1618 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1622template <
class AssignTo,
1624 enable_if_t<is_mutable_container<AssignTo>::value && (expected_count<ConvertTo>::value == 1) &&
1625 (type_count<ConvertTo>::value == 1),
1626 detail::enabler> = detail::dummy>
1627bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1630 output.reserve(strings.size());
1631 for(
const auto &elem : strings) {
1633 output.emplace_back();
1634 retval = retval && lexical_assign<typename AssignTo::value_type, ConvertTo>(elem, output.back());
1636 return (!output.empty()) && retval;
1642template <
class AssignTo,
1644 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1645 type_count_base<ConvertTo>::value == 2,
1646 detail::enabler> = detail::dummy>
1647bool lexical_conversion(std::vector<std::string> strings, AssignTo &output);
1650template <
class AssignTo,
1652 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1653 type_count_base<ConvertTo>::value != 2 &&
1654 ((type_count<ConvertTo>::value > 2) ||
1655 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1656 detail::enabler> = detail::dummy>
1657bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1660template <
class AssignTo,
1662 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1663 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1664 type_count<ConvertTo>::value > 2),
1665 detail::enabler> = detail::dummy>
1666bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1670template <
typename AssignTo,
1672 enable_if_t<!is_tuple_like<AssignTo>::value && !is_mutable_container<AssignTo>::value &&
1673 classify_object<ConvertTo>::value != object_category::wrapper_value &&
1674 (is_mutable_container<ConvertTo>::value || type_count<ConvertTo>::value > 2),
1675 detail::enabler> = detail::dummy>
1676bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1678 if(strings.size() > 1 || (!strings.empty() && !(strings.front().empty()))) {
1680 auto retval = lexical_conversion<ConvertTo, ConvertTo>(strings, val);
1681 output = AssignTo{val};
1684 output = AssignTo{};
1689template <
class AssignTo,
class ConvertTo, std::
size_t I>
1690inline typename std::enable_if<(I >= type_count_base<AssignTo>::value),
bool>::type
1691tuple_conversion(
const std::vector<std::string> &, AssignTo &) {
1696template <
class AssignTo,
class ConvertTo>
1697inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && type_count<ConvertTo>::value == 1,
bool>::type
1698tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1699 auto retval = lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1700 strings.erase(strings.begin());
1705template <
class AssignTo,
class ConvertTo>
1706inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && (type_count<ConvertTo>::value > 1) &&
1707 type_count<ConvertTo>::value == type_count_min<ConvertTo>::value,
1709tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1710 auto retval = lexical_conversion<AssignTo, ConvertTo>(strings, output);
1711 strings.erase(strings.begin(), strings.begin() + type_count<ConvertTo>::value);
1716template <
class AssignTo,
class ConvertTo>
1717inline typename std::enable_if<is_mutable_container<ConvertTo>::value ||
1718 type_count<ConvertTo>::value != type_count_min<ConvertTo>::value,
1720tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1722 std::size_t index{subtype_count_min<ConvertTo>::value};
1723 const std::size_t mx_count{subtype_count<ConvertTo>::value};
1724 const std::size_t mx{(std::min)(mx_count, strings.size() - 1)};
1727 if(is_separator(strings[index])) {
1732 bool retval = lexical_conversion<AssignTo, ConvertTo>(
1733 std::vector<std::string>(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index)), output);
1734 if(strings.size() > index) {
1735 strings.erase(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index) + 1);
1743template <
class AssignTo,
class ConvertTo, std::
size_t I>
1744inline typename std::enable_if<(I < type_count_base<AssignTo>::value),
bool>::type
1745tuple_conversion(std::vector<std::string> strings, AssignTo &output) {
1747 using ConvertToElement =
typename std::
1748 conditional<is_tuple_like<ConvertTo>::value,
typename std::tuple_element<I, ConvertTo>::type, ConvertTo>::type;
1749 if(!strings.empty()) {
1750 retval = retval && tuple_type_conversion<typename std::tuple_element<I, AssignTo>::type, ConvertToElement>(
1751 strings, std::get<I>(output));
1753 retval = retval && tuple_conversion<AssignTo, ConvertTo, I + 1>(std::move(strings), output);
1758template <
class AssignTo,
1760 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1761 type_count_base<ConvertTo>::value == 2,
1763bool lexical_conversion(std::vector<std::string> strings, AssignTo &output) {
1765 while(!strings.empty()) {
1767 typename std::remove_const<typename std::tuple_element<0, typename ConvertTo::value_type>::type>::type v1{};
1768 typename std::tuple_element<1, typename ConvertTo::value_type>::type v2{};
1769 bool retval = tuple_type_conversion<decltype(v1), decltype(v1)>(strings, v1);
1770 if(!strings.empty()) {
1771 retval = retval && tuple_type_conversion<decltype(v2), decltype(v2)>(strings, v2);
1777 output.insert(output.end(),
typename AssignTo::value_type{v1, v2});
1782 return (!output.empty());
1786template <
class AssignTo,
1788 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1789 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1790 type_count<ConvertTo>::value > 2),
1792bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1794 !is_tuple_like<ConvertTo>::value || type_count_base<AssignTo>::value == type_count_base<ConvertTo>::value,
1795 "if the conversion type is defined as a tuple it must be the same size as the type you are converting to");
1796 return tuple_conversion<AssignTo, ConvertTo, 0>(strings, output);
1800template <
class AssignTo,
1802 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1803 type_count_base<ConvertTo>::value != 2 &&
1804 ((type_count<ConvertTo>::value > 2) ||
1805 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1807bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1810 std::vector<std::string> temp;
1812 std::size_t icount{0};
1813 std::size_t xcm{type_count<ConvertTo>::value};
1814 auto ii_max = strings.size();
1815 while(ii < ii_max) {
1816 temp.push_back(strings[ii]);
1819 if(icount == xcm || is_separator(temp.back()) || ii == ii_max) {
1820 if(
static_cast<int>(xcm) > type_count_min<ConvertTo>::value && is_separator(temp.back())) {
1823 typename AssignTo::value_type temp_out;
1825 lexical_conversion<typename AssignTo::value_type, typename ConvertTo::value_type>(temp, temp_out);
1830 output.insert(output.end(), std::move(temp_out));
1838template <
typename AssignTo,
1840 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1841 std::is_assignable<ConvertTo &, ConvertTo>::value,
1842 detail::enabler> = detail::dummy>
1843bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1844 if(strings.empty() || strings.front().empty()) {
1845 output = ConvertTo{};
1848 typename ConvertTo::value_type val;
1849 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1850 output = ConvertTo{val};
1857template <
typename AssignTo,
1859 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1860 !std::is_assignable<AssignTo &, ConvertTo>::value,
1861 detail::enabler> = detail::dummy>
1862bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1863 using ConvertType =
typename ConvertTo::value_type;
1864 if(strings.empty() || strings.front().empty()) {
1865 output = ConvertType{};
1869 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1877inline std::string sum_string_vector(
const std::vector<std::string> &values) {
1880 std::int64_t ival{0};
1882 for(
const auto &arg : values) {
1884 if(!integral_conversion(arg, tv)) {
1889 if((tv > 0 && ival > (std::numeric_limits<std::int64_t>::max)() - tv) ||
1890 (tv < 0 && ival < (std::numeric_limits<std::int64_t>::min)() - tv)) {
1897 return std::to_string(ival);
1903 for(
const auto &arg : values) {
1905 auto comp = lexical_cast(arg, tv);
1908 auto fv = detail::to_flag_value(arg);
1909 fail = (errno != 0);
1913 tv =
static_cast<double>(fv);
1918 for(
const auto &arg : values) {
1922 std::ostringstream out;
Definition TypeTools.hpp:99
Check for complex.
Definition TypeTools.hpp:238
Definition TypeTools.hpp:180
Check for input streamability.
Definition TypeTools.hpp:227
Definition TypeTools.hpp:216
Definition TypeTools.hpp:302
This can be specialized to override the type deduction for IsMember.
Definition TypeTools.hpp:84
not a pointer
Definition TypeTools.hpp:118
Definition TypeTools.hpp:128
Definition TypeTools.hpp:263
Definition TypeTools.hpp:283
Definition TypeTools.hpp:294
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:160
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:164
Adaptor for set-like structure: This just wraps a normal container in a few utilities that do almost ...
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:143
static auto first(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the first value (really just the underlying value).
Definition TypeTools.hpp:139
forward declare the subtype_count_min structure
Definition TypeTools.hpp:504
Set of overloads to get the type size of an object.
Definition TypeTools.hpp:501
This will only trigger for actual void type.
Definition TypeTools.hpp:314
This will only trigger for actual void type.
Definition TypeTools.hpp:507
template to get the underlying value type if it exists or use a default
Definition TypeTools.hpp:489
Check to see if something is bool (fail check by default).
Definition TypeTools.hpp:64
Check to see if something is copyable pointer.
Definition TypeTools.hpp:79
Check to see if something is a shared pointer.
Definition TypeTools.hpp:70
A copy of std::void_t from C++17 (helper for C++11 and C++14).
Definition TypeTools.hpp:53