26#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);
1080CLI11_INLINE std::int64_t to_flag_value(std::string val)
noexcept;
1083template <
typename T,
1084 enable_if_t<classify_object<T>::value == object_category::integral_value ||
1085 classify_object<T>::value == object_category::unsigned_integral,
1086 detail::enabler> = detail::dummy>
1087bool lexical_cast(
const std::string &input, T &output) {
1088 return integral_conversion(input, output);
1092template <
typename T,
1093 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> = detail::dummy>
1094bool lexical_cast(
const std::string &input, T &output) {
1095 if(input.size() == 1) {
1096 output =
static_cast<T
>(input[0]);
1102 bool result = integral_conversion(input, res);
1104 output =
static_cast<T
>(res);
1110template <
typename T,
1111 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
1112bool lexical_cast(
const std::string &input, T &output) {
1114 auto out = to_flag_value(input);
1117 }
else if(errno == ERANGE) {
1118 output = (input[0] !=
'-');
1126template <
typename T,
1127 enable_if_t<classify_object<T>::value == object_category::floating_point, detail::enabler> = detail::dummy>
1128bool lexical_cast(
const std::string &input, T &output) {
1132 char *val =
nullptr;
1133 auto output_ld = std::strtold(input.c_str(), &val);
1136 if(val == input.c_str()) {
1139 output =
static_cast<T
>(output_ld);
1140 if(val == (input.c_str() + input.size())) {
1143 while(std::isspace(
static_cast<unsigned char>(*val))) {
1145 if(val == (input.c_str() + input.size())) {
1151 auto group_separators = get_group_separators();
1152 if(input.find_first_of(group_separators) != std::string::npos) {
1153 for(
auto &separator : group_separators) {
1154 if(input.find_first_of(separator) != std::string::npos) {
1155 std::string nstring = input;
1156 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1157 return lexical_cast(nstring, output);
1165template <
typename T,
1166 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
1167bool lexical_cast(
const std::string &input, T &output) {
1168 using XC =
typename wrapped_type<T, double>::type;
1171 bool worked =
false;
1172 auto nloc = str1.find_last_of(
"+-");
1173 if(nloc != std::string::npos && nloc > 0) {
1174 worked = lexical_cast(str1.substr(0, nloc), x);
1175 str1 = str1.substr(nloc);
1176 if(str1.back() ==
'i' || str1.back() ==
'j')
1178 worked = worked && lexical_cast(str1, y);
1180 if(str1.back() ==
'i' || str1.back() ==
'j') {
1182 worked = lexical_cast(str1, y);
1185 worked = lexical_cast(str1, x);
1193 return from_stream(input, output);
1197template <
typename T,
1198 enable_if_t<classify_object<T>::value == object_category::string_assignable, detail::enabler> = detail::dummy>
1199bool lexical_cast(
const std::string &input, T &output) {
1207 enable_if_t<classify_object<T>::value == object_category::string_constructible, detail::enabler> = detail::dummy>
1208bool lexical_cast(
const std::string &input, T &output) {
1216 enable_if_t<classify_object<T>::value == object_category::wstring_assignable, detail::enabler> = detail::dummy>
1217bool lexical_cast(
const std::string &input, T &output) {
1218 output = widen(input);
1224 enable_if_t<classify_object<T>::value == object_category::wstring_constructible, detail::enabler> = detail::dummy>
1225bool lexical_cast(
const std::string &input, T &output) {
1226 output = T{widen(input)};
1231template <
typename T,
1232 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
1233bool lexical_cast(
const std::string &input, T &output) {
1234 typename std::underlying_type<T>::type val;
1235 if(!integral_conversion(input, val)) {
1238 output =
static_cast<T
>(val);
1243template <
typename T,
1244 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1245 std::is_assignable<T &, typename T::value_type>::value,
1246 detail::enabler> = detail::dummy>
1247bool lexical_cast(
const std::string &input, T &output) {
1248 typename T::value_type val;
1249 if(lexical_cast(input, val)) {
1253 return from_stream(input, output);
1256template <
typename T,
1257 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1258 !std::is_assignable<T &, typename T::value_type>::value && std::is_assignable<T &, T>::value,
1259 detail::enabler> = detail::dummy>
1260bool lexical_cast(
const std::string &input, T &output) {
1261 typename T::value_type val;
1262 if(lexical_cast(input, val)) {
1266 return from_stream(input, output);
1272 enable_if_t<classify_object<T>::value == object_category::number_constructible, detail::enabler> = detail::dummy>
1273bool lexical_cast(
const std::string &input, T &output) {
1275 if(integral_conversion(input, val)) {
1281 if(lexical_cast(input, dval)) {
1286 return from_stream(input, output);
1292 enable_if_t<classify_object<T>::value == object_category::integer_constructible, detail::enabler> = detail::dummy>
1293bool lexical_cast(
const std::string &input, T &output) {
1295 if(integral_conversion(input, val)) {
1299 return from_stream(input, output);
1305 enable_if_t<classify_object<T>::value == object_category::double_constructible, detail::enabler> = detail::dummy>
1306bool lexical_cast(
const std::string &input, T &output) {
1308 if(lexical_cast(input, val)) {
1312 return from_stream(input, output);
1316template <
typename T,
1317 enable_if_t<classify_object<T>::value == object_category::other && std::is_assignable<T &, int>::value,
1318 detail::enabler> = detail::dummy>
1319bool lexical_cast(
const std::string &input, T &output) {
1321 if(integral_conversion(input, val)) {
1323#pragma warning(push)
1324#pragma warning(disable : 4800)
1337 return from_stream(input, output);
1342template <
typename T,
1343 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1344 is_istreamable<T>::value,
1345 detail::enabler> = detail::dummy>
1346bool lexical_cast(
const std::string &input, T &output) {
1347 return from_stream(input, output);
1352template <
typename T,
1353 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1354 !is_istreamable<T>::value && !adl_detail::is_lexical_castable<T>::value,
1355 detail::enabler> = detail::dummy>
1356bool lexical_cast(
const std::string & , T & ) {
1357 static_assert(!std::is_same<T, T>::value,
1358 "option object type must have a lexical cast overload or streaming input operator(>>) defined, if it "
1359 "is convertible from another type use the add_option<T, XC>(...) with XC being the known type");
1365template <
typename AssignTo,
1367 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !is_wrapper<AssignTo>::value &&
1368 (classify_object<AssignTo>::value == object_category::string_assignable ||
1369 classify_object<AssignTo>::value == object_category::string_constructible ||
1370 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1371 classify_object<AssignTo>::value == object_category::wstring_constructible),
1372 detail::enabler> = detail::dummy>
1373bool lexical_assign(
const std::string &input, AssignTo &output) {
1374 return lexical_cast(input, output);
1379template <
typename AssignTo,
1381 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && is_wrapper<AssignTo>::value &&
1382 (classify_object<AssignTo>::value == object_category::string_assignable ||
1383 classify_object<AssignTo>::value == object_category::string_constructible ||
1384 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1385 classify_object<AssignTo>::value == object_category::wstring_constructible),
1386 detail::enabler> = detail::dummy>
1387bool lexical_assign(
const std::string &input, AssignTo &output) {
1389 output = AssignTo{};
1392 return lexical_cast(input, output);
1396template <
typename AssignTo,
1398 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, AssignTo>::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,
1403 detail::enabler> = detail::dummy>
1404bool lexical_assign(
const std::string &input, AssignTo &output) {
1406 output = AssignTo{};
1410 return lexical_cast(input, output);
1414template <
typename AssignTo,
1416 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1417 classify_object<AssignTo>::value == object_category::wrapper_value,
1418 detail::enabler> = detail::dummy>
1419bool lexical_assign(
const std::string &input, AssignTo &output) {
1421 typename AssignTo::value_type emptyVal{};
1425 return lexical_cast(input, output);
1430template <
typename AssignTo,
1432 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1433 classify_object<AssignTo>::value != object_category::wrapper_value &&
1434 std::is_assignable<AssignTo &, int>::value,
1435 detail::enabler> = detail::dummy>
1436bool lexical_assign(
const std::string &input, AssignTo &output) {
1442 if(lexical_cast(input, val)) {
1443#if defined(__clang__)
1445#pragma clang diagnostic push
1446#pragma clang diagnostic ignored "-Wsign-conversion"
1447#elif defined(__GNUC__) && (__GNUC__ == 8)
1449#pragma GCC diagnostic push
1450#pragma GCC diagnostic ignored "-Wsign-conversion"
1453#if defined(__clang__)
1454#pragma clang diagnostic pop
1455#elif defined(__GNUC__) && (__GNUC__ == 8)
1456#pragma GCC diagnostic pop
1464template <
typename AssignTo,
1466 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, ConvertTo &>::value,
1467 detail::enabler> = detail::dummy>
1468bool lexical_assign(
const std::string &input, AssignTo &output) {
1470 bool parse_result = (!input.empty()) ? lexical_cast(input, val) : true;
1474 return parse_result;
1481 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, ConvertTo &>::value &&
1482 std::is_move_assignable<AssignTo>::value,
1483 detail::enabler> = detail::dummy>
1484bool lexical_assign(
const std::string &input, AssignTo &output) {
1486 bool parse_result = input.empty() ? true : lexical_cast(input, val);
1488 output = AssignTo(val);
1490 return parse_result;
1494template <
typename AssignTo,
1496 enable_if_t<classify_object<ConvertTo>::value <= object_category::other &&
1497 classify_object<AssignTo>::value <= object_category::wrapper_value,
1498 detail::enabler> = detail::dummy>
1499bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1500 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1505template <
typename AssignTo,
1507 enable_if_t<(type_count<AssignTo>::value <= 2) && expected_count<AssignTo>::value == 1 &&
1508 is_tuple_like<ConvertTo>::value && type_count_base<ConvertTo>::value == 2,
1509 detail::enabler> = detail::dummy>
1510bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1512 using FirstType =
typename std::remove_const<typename std::tuple_element<0, ConvertTo>::type>::type;
1513 using SecondType =
typename std::tuple_element<1, ConvertTo>::type;
1516 bool retval = lexical_assign<FirstType, FirstType>(strings[0], v1);
1517 retval = retval && lexical_assign<SecondType, SecondType>((strings.size() > 1) ? strings[1] : std::string{}, v2);
1519 output = AssignTo{v1, v2};
1525template <
class AssignTo,
1527 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1528 type_count<ConvertTo>::value == 1,
1529 detail::enabler> = detail::dummy>
1530bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1531 output.erase(output.begin(), output.end());
1532 if(strings.empty()) {
1535 if(strings.size() == 1 && strings[0] ==
"{}") {
1538 bool skip_remaining =
false;
1539 if(strings.size() == 2 && strings[0] ==
"{}" && is_separator(strings[1])) {
1540 skip_remaining =
true;
1542 for(
const auto &elem : strings) {
1543 typename AssignTo::value_type out;
1544 bool retval = lexical_assign<typename AssignTo::value_type, typename ConvertTo::value_type>(elem, out);
1548 output.insert(output.end(), std::move(out));
1549 if(skip_remaining) {
1553 return (!output.empty());
1557template <class AssignTo, class ConvertTo, enable_if_t<is_complex<ConvertTo>::value, detail::enabler> = detail::dummy>
1558bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1560 if(strings.size() >= 2 && !strings[1].empty()) {
1561 using XC2 =
typename wrapped_type<ConvertTo, double>::type;
1563 auto str1 = strings[1];
1564 if(str1.back() ==
'i' || str1.back() ==
'j') {
1567 auto worked = lexical_cast(strings[0], x) && lexical_cast(str1, y);
1569 output = ConvertTo{x, y};
1573 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1577template <
class AssignTo,
1579 enable_if_t<is_mutable_container<AssignTo>::value && (expected_count<ConvertTo>::value == 1) &&
1580 (type_count<ConvertTo>::value == 1),
1581 detail::enabler> = detail::dummy>
1582bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1585 output.reserve(strings.size());
1586 for(
const auto &elem : strings) {
1588 output.emplace_back();
1589 retval = retval && lexical_assign<typename AssignTo::value_type, ConvertTo>(elem, output.back());
1591 return (!output.empty()) && retval;
1597template <
class AssignTo,
1599 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1600 type_count_base<ConvertTo>::value == 2,
1601 detail::enabler> = detail::dummy>
1602bool lexical_conversion(std::vector<std::string> strings, AssignTo &output);
1605template <
class AssignTo,
1607 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1608 type_count_base<ConvertTo>::value != 2 &&
1609 ((type_count<ConvertTo>::value > 2) ||
1610 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1611 detail::enabler> = detail::dummy>
1612bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1615template <
class AssignTo,
1617 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1618 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1619 type_count<ConvertTo>::value > 2),
1620 detail::enabler> = detail::dummy>
1621bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1625template <
typename AssignTo,
1627 enable_if_t<!is_tuple_like<AssignTo>::value && !is_mutable_container<AssignTo>::value &&
1628 classify_object<ConvertTo>::value != object_category::wrapper_value &&
1629 (is_mutable_container<ConvertTo>::value || type_count<ConvertTo>::value > 2),
1630 detail::enabler> = detail::dummy>
1631bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1633 if(strings.size() > 1 || (!strings.empty() && !(strings.front().empty()))) {
1635 auto retval = lexical_conversion<ConvertTo, ConvertTo>(strings, val);
1636 output = AssignTo{val};
1639 output = AssignTo{};
1644template <
class AssignTo,
class ConvertTo, std::
size_t I>
1645inline typename std::enable_if<(I >= type_count_base<AssignTo>::value),
bool>::type
1646tuple_conversion(
const std::vector<std::string> &, AssignTo &) {
1651template <
class AssignTo,
class ConvertTo>
1652inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && type_count<ConvertTo>::value == 1,
bool>::type
1653tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1654 auto retval = lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1655 strings.erase(strings.begin());
1660template <
class AssignTo,
class ConvertTo>
1661inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && (type_count<ConvertTo>::value > 1) &&
1662 type_count<ConvertTo>::value == type_count_min<ConvertTo>::value,
1664tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1665 auto retval = lexical_conversion<AssignTo, ConvertTo>(strings, output);
1666 strings.erase(strings.begin(), strings.begin() + type_count<ConvertTo>::value);
1671template <
class AssignTo,
class ConvertTo>
1672inline typename std::enable_if<is_mutable_container<ConvertTo>::value ||
1673 type_count<ConvertTo>::value != type_count_min<ConvertTo>::value,
1675tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1677 std::size_t index{subtype_count_min<ConvertTo>::value};
1678 const std::size_t mx_count{subtype_count<ConvertTo>::value};
1679 const std::size_t mx{(std::min)(mx_count, strings.size() - 1)};
1682 if(is_separator(strings[index])) {
1687 bool retval = lexical_conversion<AssignTo, ConvertTo>(
1688 std::vector<std::string>(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index)), output);
1689 if(strings.size() > index) {
1690 strings.erase(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index) + 1);
1698template <
class AssignTo,
class ConvertTo, std::
size_t I>
1699inline typename std::enable_if<(I < type_count_base<AssignTo>::value),
bool>::type
1700tuple_conversion(std::vector<std::string> strings, AssignTo &output) {
1702 using ConvertToElement =
typename std::
1703 conditional<is_tuple_like<ConvertTo>::value,
typename std::tuple_element<I, ConvertTo>::type, ConvertTo>::type;
1704 if(!strings.empty()) {
1705 retval = retval && tuple_type_conversion<typename std::tuple_element<I, AssignTo>::type, ConvertToElement>(
1706 strings, std::get<I>(output));
1708 retval = retval && tuple_conversion<AssignTo, ConvertTo, I + 1>(std::move(strings), output);
1713template <
class AssignTo,
1715 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1716 type_count_base<ConvertTo>::value == 2,
1718bool lexical_conversion(std::vector<std::string> strings, AssignTo &output) {
1720 while(!strings.empty()) {
1722 typename std::remove_const<typename std::tuple_element<0, typename ConvertTo::value_type>::type>::type v1{};
1723 typename std::tuple_element<1, typename ConvertTo::value_type>::type v2{};
1724 bool retval = tuple_type_conversion<decltype(v1), decltype(v1)>(strings, v1);
1725 if(!strings.empty()) {
1726 retval = retval && tuple_type_conversion<decltype(v2), decltype(v2)>(strings, v2);
1732 output.insert(output.end(),
typename AssignTo::value_type{v1, v2});
1737 return (!output.empty());
1741template <
class AssignTo,
1743 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1744 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1745 type_count<ConvertTo>::value > 2),
1747bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1749 !is_tuple_like<ConvertTo>::value || type_count_base<AssignTo>::value == type_count_base<ConvertTo>::value,
1750 "if the conversion type is defined as a tuple it must be the same size as the type you are converting to");
1751 return tuple_conversion<AssignTo, ConvertTo, 0>(strings, output);
1755template <
class AssignTo,
1757 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1758 type_count_base<ConvertTo>::value != 2 &&
1759 ((type_count<ConvertTo>::value > 2) ||
1760 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1762bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1765 std::vector<std::string> temp;
1767 std::size_t icount{0};
1768 std::size_t xcm{type_count<ConvertTo>::value};
1769 auto ii_max = strings.size();
1770 while(ii < ii_max) {
1771 temp.push_back(strings[ii]);
1774 if(icount == xcm || is_separator(temp.back()) || ii == ii_max) {
1775 if(
static_cast<int>(xcm) > type_count_min<ConvertTo>::value && is_separator(temp.back())) {
1778 typename AssignTo::value_type temp_out;
1780 lexical_conversion<typename AssignTo::value_type, typename ConvertTo::value_type>(temp, temp_out);
1785 output.insert(output.end(), std::move(temp_out));
1793template <
typename AssignTo,
1795 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1796 std::is_assignable<ConvertTo &, ConvertTo>::value,
1797 detail::enabler> = detail::dummy>
1798bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1799 if(strings.empty() || strings.front().empty()) {
1800 output = ConvertTo{};
1803 typename ConvertTo::value_type val;
1804 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1805 output = ConvertTo{val};
1812template <
typename AssignTo,
1814 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1815 !std::is_assignable<AssignTo &, ConvertTo>::value,
1816 detail::enabler> = detail::dummy>
1817bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1818 using ConvertType =
typename ConvertTo::value_type;
1819 if(strings.empty() || strings.front().empty()) {
1820 output = ConvertType{};
1824 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1832CLI11_INLINE std::string sum_string_vector(
const std::vector<std::string> &values);
1838#ifndef CLI11_COMPILE
1839#include "impl/TypeTools_inl.hpp"
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