29#include "Encoding.hpp"
31#include "StringTools.hpp"
42enum class enabler : std::uint8_t {};
45CLI11_MODULE_INLINE
constexpr enabler dummy = {};
53template <
bool B,
class T =
void>
using enable_if_t =
typename std::enable_if<B, T>::type;
61template <
typename... Ts>
using void_t =
typename make_void<Ts...>::type;
64template <
bool B,
class T,
class F>
using conditional_t =
typename std::conditional<B, T, F>::type;
67template <
typename T>
struct is_bool : std::false_type {};
70template <>
struct is_bool<bool> : std::true_type {};
76template <
typename T>
struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
79template <
typename T>
struct is_shared_ptr<const std::shared_ptr<T>> : std::true_type {};
93 using type = std::string;
103 template <
typename TT,
typename SS>
104 static auto test(
int) ->
decltype(lexical_cast(std::declval<const SS &>(), std::declval<TT &>()), std::true_type());
106 template <
typename,
typename>
static auto test(...) -> std::false_type;
109 static constexpr bool value =
decltype(test<T, S>(0))::value;
125template <
typename T>
struct element_type<T, typename std::enable_if<is_copyable_ptr<T>::value>::type> {
126 using type =
typename std::pointer_traits<T>::element_type;
136template <
typename T,
typename _ =
void>
struct pair_adaptor : std::false_type {
137 using value_type =
typename T::value_type;
138 using first_type =
typename std::remove_const<value_type>::type;
139 using second_type =
typename std::remove_const<value_type>::type;
142 template <
typename Q>
static auto first(Q &&pair_value) ->
decltype(std::forward<Q>(pair_value)) {
143 return std::forward<Q>(pair_value);
146 template <
typename Q>
static auto second(Q &&pair_value) ->
decltype(std::forward<Q>(pair_value)) {
147 return std::forward<Q>(pair_value);
156 conditional_t<false, void_t<typename T::value_type::first_type, typename T::value_type::second_type>, void>>
158 using value_type =
typename T::value_type;
159 using first_type =
typename std::remove_const<typename value_type::first_type>::type;
160 using second_type =
typename std::remove_const<typename value_type::second_type>::type;
163 template <
typename Q>
static auto first(Q &&pair_value) ->
decltype(std::get<0>(std::forward<Q>(pair_value))) {
164 return std::get<0>(std::forward<Q>(pair_value));
167 template <
typename Q>
static auto second(Q &&pair_value) ->
decltype(std::get<1>(std::forward<Q>(pair_value))) {
168 return std::get<1>(std::forward<Q>(pair_value));
179#pragma GCC diagnostic push
180#pragma GCC diagnostic ignored "-Wnarrowing"
184 template <
typename TT,
typename CC>
185 static auto test(
int, std::true_type) ->
decltype(
188#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
189#pragma nv_diag_suppress 2361
191#pragma diag_suppress 2361
194 TT{std::declval<CC>()}
196#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
197#pragma nv_diag_default 2361
199#pragma diag_default 2361
203 std::is_move_assignable<TT>());
205 template <
typename TT,
typename CC>
static auto test(
int, std::false_type) -> std::false_type;
207 template <
typename,
typename>
static auto test(...) -> std::false_type;
210 static constexpr bool value =
decltype(test<T, C>(0,
typename std::is_constructible<T, C>::type()))::value;
213#pragma GCC diagnostic pop
220 template <
typename TT,
typename SS>
221 static auto test(
int) ->
decltype(std::declval<SS &>() << std::declval<TT>(), std::true_type());
223 template <
typename,
typename>
static auto test(...) -> std::false_type;
226 static constexpr bool value =
decltype(test<T, S>(0))::value;
231 template <
typename TT,
typename SS>
232 static auto test(
int) ->
decltype(std::declval<SS &>() >> std::declval<TT &>(), std::true_type());
234 template <
typename,
typename>
static auto test(...) -> std::false_type;
237 static constexpr bool value =
decltype(test<T, S>(0))::value;
242 template <
typename TT>
243 static auto test(
int) ->
decltype(std::declval<TT>().real(), std::declval<TT>().imag(), std::true_type());
245 template <
typename>
static auto test(...) -> std::false_type;
248 static constexpr bool value =
decltype(test<T>(0))::value;
252template <typename T, enable_if_t<is_istreamable<T>::value, detail::enabler> = detail::dummy>
253bool from_stream(
const std::string &istring, T &obj) {
254 std::istringstream is;
257 return !is.fail() && !is.rdbuf()->in_avail();
260template <typename T, enable_if_t<!is_istreamable<T>::value, detail::enabler> = detail::dummy>
261bool from_stream(
const std::string & , T & ) {
275 void_t<typename T::value_type,
276 decltype(std::declval<T>().end()),
277 decltype(std::declval<T>().clear()),
278 decltype(std::declval<T>().insert(std::declval<decltype(std::declval<T>().end())>(),
279 std::declval<const typename T::value_type &>()))>,
280 void>> :
public conditional_t<std::is_constructible<T, std::string>::value ||
281 std::is_constructible<T, std::wstring>::value,
293 conditional_t<false, void_t<decltype(std::declval<T>().end()), decltype(std::declval<T>().begin())>, void>>
294 :
public std::true_type {};
297template <
typename T,
typename _ =
void>
struct is_wrapper : std::false_type {};
301struct is_wrapper<T, conditional_t<false, void_t<typename T::value_type>, void>> :
public std::true_type {};
306 template <typename SS, enable_if_t<!is_complex<SS>::value, detail::enabler> = detail::dummy>
309 static auto test(
int) ->
decltype(std::tuple_size<typename std::decay<SS>::type>::value, std::true_type{});
310 template <
typename>
static auto test(...) -> std::false_type;
313 static constexpr bool value =
decltype(test<S>(0))::value;
318 static const int value{0};
324 typename std::enable_if<!is_tuple_like<T>::value && !is_mutable_container<T>::value &&
325 !std::is_void<T>::value>::type> {
326 static constexpr int value{1};
331struct type_count_base<T, typename std::enable_if<is_tuple_like<T>::value && !is_mutable_container<T>::value>::type> {
332 static constexpr int value{
333 std::tuple_size<typename std::decay<T>::type>::value};
337template <
typename T>
struct type_count_base<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
338 static constexpr int value{type_count_base<typename T::value_type>::value};
342template <typename T, enable_if_t<std::is_convertible<T, std::string>::value, detail::enabler> = detail::dummy>
343auto to_string(T &&value) ->
decltype(std::forward<T>(value)) {
344 return std::forward<T>(value);
349 enable_if_t<std::is_constructible<std::string, T>::value && !std::is_convertible<T, std::string>::value,
350 detail::enabler> = detail::dummy>
351std::string to_string(T &&value) {
352 return std::string(value);
356 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
357 is_ostreamable<T>::value && std::is_floating_point<typename std::decay<T>::type>::value,
358 detail::enabler> = detail::dummy>
359std::string to_string(T &&value) {
360 std::ostringstream stream;
361 stream << std::setprecision(std::numeric_limits<
typename std::decay<T>::type>::max_digits10) << value;
367 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
368 is_ostreamable<T>::value && !std::is_floating_point<typename std::decay<T>::type>::value,
369 detail::enabler> = detail::dummy>
370std::string to_string(T &&value) {
371 std::stringstream stream;
380 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
381 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value == 1,
382 detail::enabler> = detail::dummy>
383inline std::string to_string(T &&value);
387 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
388 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value >= 2,
389 detail::enabler> = detail::dummy>
390inline std::string to_string(T &&value);
395 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
397 !is_tuple_like<T>::value,
398 detail::enabler> = detail::dummy>
399inline std::string to_string(T &&) {
405 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
407 detail::enabler> = detail::dummy>
408inline std::string to_string(T &&variable) {
409 auto cval = variable.begin();
410 auto end = variable.end();
414 std::vector<std::string> defaults;
416 defaults.emplace_back(CLI::detail::to_string(*cval));
419 return {
"[" + detail::join(defaults) +
"]"};
425template <
typename T, std::
size_t I>
426inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_value_string(T && );
429template <
typename T, std::
size_t I>
430inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_value_string(T &&value);
434 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
435 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value == 1,
437inline std::string to_string(T &&value) {
438 return to_string(std::get<0>(value));
443 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
444 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value >= 2,
446inline std::string to_string(T &&value) {
447 auto tname = std::string(1,
'[') + tuple_value_string<T, 0>(value);
448 tname.push_back(
']');
453template <
typename T, std::
size_t I>
454inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_value_string(T && ) {
455 return std::string{};
459template <
typename T, std::
size_t I>
460inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_value_string(T &&value) {
461 auto str = std::string{to_string(std::get<I>(value))} +
',' + tuple_value_string<T, I + 1>(value);
462 if(str.back() ==
',')
468template <
typename T1,
471 enable_if_t<std::is_same<T1, T2>::value, detail::enabler> = detail::dummy>
472auto checked_to_string(T &&value) ->
decltype(to_string(std::forward<T>(value))) {
473 return to_string(std::forward<T>(value));
477template <
typename T1,
480 enable_if_t<!std::is_same<T1, T2>::value, detail::enabler> = detail::dummy>
481std::string checked_to_string(T &&) {
482 return std::string{};
485template <typename T, enable_if_t<std::is_integral<T>::value, detail::enabler> = detail::dummy>
486std::string value_string(
const T &value) {
487 return std::to_string(value);
491template <typename T, enable_if_t<std::is_floating_point<T>::value, detail::enabler> = detail::dummy>
492std::string value_string(
const T &value) {
493 std::ostringstream stream;
494 stream << std::setprecision(std::numeric_limits<T>::max_digits10) << value;
499template <typename T, enable_if_t<std::is_enum<T>::value, detail::enabler> = detail::dummy>
500std::string value_string(
const T &value) {
501 return std::to_string(
static_cast<typename std::underlying_type<T>::type
>(value));
505 enable_if_t<!std::is_enum<T>::value && !std::is_arithmetic<T>::value, detail::enabler> = detail::dummy>
506auto value_string(
const T &value) ->
decltype(to_string(value)) {
507 return to_string(value);
511template <
typename T,
typename def,
typename Enable =
void>
struct wrapped_type {
516template <
typename T,
typename def>
struct wrapped_type<T, def, typename std::enable_if<is_wrapper<T>::value>::type> {
517 using type =
typename T::value_type;
529template <
typename T,
typename Enable =
void>
struct type_count {
530 static const int value{0};
536 typename std::enable_if<!is_wrapper<T>::value && !is_tuple_like<T>::value && !is_complex<T>::value &&
537 !std::is_void<T>::value>::type> {
538 static constexpr int value{1};
542template <
typename T>
struct type_count<T, typename std::enable_if<is_complex<T>::value>::type> {
543 static constexpr int value{2};
547template <
typename T>
struct type_count<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
554 typename std::enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value &&
555 !is_mutable_container<T>::value>::type> {
556 static constexpr int value{type_count<typename T::value_type>::value};
560template <
typename T, std::
size_t I>
561constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type tuple_type_size() {
566template <
typename T, std::
size_t I>
567 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type tuple_type_size() {
568 return subtype_count<typename std::tuple_element<I, T>::type>::value + tuple_type_size<T, I + 1>();
573struct type_count<T, typename std::enable_if<is_tuple_like<T>::value && !is_complex<T>::value>::type> {
574 static constexpr int value{tuple_type_size<T, 0>()};
579 static constexpr int value{is_mutable_container<T>::value ? expected_max_vector_size : type_count<T>::value};
583template <
typename T,
typename Enable =
void>
struct type_count_min {
584 static const int value{0};
589struct type_count_min<
591 typename std::enable_if<!is_mutable_container<T>::value && !is_tuple_like<T>::value && !is_wrapper<T>::value &&
592 !is_complex<T>::value && !std::is_void<T>::value>::type> {
593 static constexpr int value{type_count<T>::value};
597template <
typename T>
struct type_count_min<T, typename std::enable_if<is_complex<T>::value>::type> {
598 static constexpr int value{1};
603struct type_count_min<
605 typename std::enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value>::type> {
606 static constexpr int value{subtype_count_min<typename T::value_type>::value};
610template <
typename T, std::
size_t I>
611constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type tuple_type_size_min() {
616template <
typename T, std::
size_t I>
617 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type tuple_type_size_min() {
623struct type_count_min<T, typename std::enable_if<is_tuple_like<T>::value && !is_complex<T>::value>::type> {
624 static constexpr int value{tuple_type_size_min<T, 0>()};
629 static constexpr int value{is_mutable_container<T>::value
630 ? ((type_count<T>::value < expected_max_vector_size) ? type_count<T>::value : 0)
631 : type_count_min<T>::value};
635template <
typename T,
typename Enable =
void>
struct expected_count {
636 static const int value{0};
641struct expected_count<T,
642 typename std::enable_if<!is_mutable_container<T>::value && !is_wrapper<T>::value &&
643 !std::is_void<T>::value>::type> {
644 static constexpr int value{1};
647template <
typename T>
struct expected_count<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
648 static constexpr int value{expected_max_vector_size};
653struct expected_count<T, typename std::enable_if<!is_mutable_container<T>::value && is_wrapper<T>::value>::type> {
654 static constexpr int value{expected_count<typename T::value_type>::value};
658enum class object_category : std::uint8_t {
661 unsigned_integral = 4,
665 number_constructible = 12,
666 double_constructible = 14,
667 integer_constructible = 16,
669 string_assignable = 23,
670 string_constructible = 24,
671 wstring_assignable = 25,
672 wstring_constructible = 26,
678 container_value = 80,
685template <
typename T,
typename Enable =
void>
struct classify_object {
686 static constexpr object_category value{object_category::other};
691struct classify_object<
693 typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, char>::value && std::is_signed<T>::value &&
694 !is_bool<T>::value && !std::is_enum<T>::value>::type> {
695 static constexpr object_category value{object_category::integral_value};
700struct classify_object<T,
701 typename std::enable_if<std::is_integral<T>::value && std::is_unsigned<T>::value &&
702 !std::is_same<T, char>::value && !is_bool<T>::value>::type> {
703 static constexpr object_category value{object_category::unsigned_integral};
708struct classify_object<T, typename std::enable_if<std::is_same<T, char>::value && !std::is_enum<T>::value>::type> {
709 static constexpr object_category value{object_category::char_value};
713template <
typename T>
struct classify_object<T, typename std::enable_if<is_bool<T>::value>::type> {
714 static constexpr object_category value{object_category::boolean_value};
718template <
typename T>
struct classify_object<T, typename std::enable_if<std::is_floating_point<T>::value>::type> {
719 static constexpr object_category value{object_category::floating_point};
724#define WIDE_STRING_CHECK \
725 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value
726#define STRING_CHECK true
728#define WIDE_STRING_CHECK true
729#define STRING_CHECK !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value
734struct classify_object<
736 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value && WIDE_STRING_CHECK &&
737 std::is_assignable<T &, std::string>::value>::type> {
738 static constexpr object_category value{object_category::string_assignable};
743struct classify_object<
745 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
746 !std::is_assignable<T &, std::string>::value && (type_count<T>::value == 1) &&
747 WIDE_STRING_CHECK && std::is_constructible<T, std::string>::value>::type> {
748 static constexpr object_category value{object_category::string_constructible};
753struct classify_object<T,
754 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
755 STRING_CHECK && std::is_assignable<T &, std::wstring>::value>::type> {
756 static constexpr object_category value{object_category::wstring_assignable};
760struct classify_object<
762 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
763 !std::is_assignable<T &, std::wstring>::value && (type_count<T>::value == 1) &&
764 STRING_CHECK && std::is_constructible<T, std::wstring>::value>::type> {
765 static constexpr object_category value{object_category::wstring_constructible};
769template <
typename T>
struct classify_object<T, typename std::enable_if<std::is_enum<T>::value>::type> {
770 static constexpr object_category value{object_category::enumeration};
773template <
typename T>
struct classify_object<T, typename std::enable_if<is_complex<T>::value>::type> {
774 static constexpr object_category value{object_category::complex_number};
779template <
typename T>
struct uncommon_type {
780 using type =
typename std::conditional<
781 !std::is_floating_point<T>::value && !std::is_integral<T>::value &&
782 !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value &&
783 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value &&
784 !is_complex<T>::value && !is_mutable_container<T>::value && !std::is_enum<T>::value,
786 std::false_type>::type;
787 static constexpr bool value = type::value;
792struct classify_object<T,
793 typename std::enable_if<(!is_mutable_container<T>::value && is_wrapper<T>::value &&
794 !is_tuple_like<T>::value && uncommon_type<T>::value)>::type> {
795 static constexpr object_category value{object_category::wrapper_value};
800struct classify_object<T,
801 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
802 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
803 is_direct_constructible<T, int>::value>::type> {
804 static constexpr object_category value{object_category::number_constructible};
809struct classify_object<T,
810 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
811 !is_wrapper<T>::value && !is_direct_constructible<T, double>::value &&
812 is_direct_constructible<T, int>::value>::type> {
813 static constexpr object_category value{object_category::integer_constructible};
818struct classify_object<T,
819 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
820 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
821 !is_direct_constructible<T, int>::value>::type> {
822 static constexpr object_category value{object_category::double_constructible};
827struct classify_object<
829 typename std::enable_if<is_tuple_like<T>::value &&
830 ((type_count<T>::value >= 2 && !is_wrapper<T>::value) ||
831 (uncommon_type<T>::value && !is_direct_constructible<T, double>::value &&
832 !is_direct_constructible<T, int>::value) ||
833 (uncommon_type<T>::value && type_count<T>::value >= 2))>::type> {
834 static constexpr object_category value{object_category::tuple_value};
843template <
typename T>
struct classify_object<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
844 static constexpr object_category value{object_category::container_value};
854 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> = detail::dummy>
855constexpr const char *type_name() {
860 enable_if_t<classify_object<T>::value == object_category::integral_value ||
861 classify_object<T>::value == object_category::integer_constructible,
862 detail::enabler> = detail::dummy>
863constexpr const char *type_name() {
868 enable_if_t<classify_object<T>::value == object_category::unsigned_integral, detail::enabler> = detail::dummy>
869constexpr const char *type_name() {
874 enable_if_t<classify_object<T>::value == object_category::floating_point ||
875 classify_object<T>::value == object_category::number_constructible ||
876 classify_object<T>::value == object_category::double_constructible,
877 detail::enabler> = detail::dummy>
878constexpr const char *type_name() {
884 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
885constexpr const char *type_name() {
891 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
892constexpr const char *type_name() {
898 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
899constexpr const char *type_name() {
905 enable_if_t<classify_object<T>::value >= object_category::string_assignable &&
906 classify_object<T>::value <= object_category::other,
907 detail::enabler> = detail::dummy>
908constexpr const char *type_name() {
913 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value >= 2,
914 detail::enabler> = detail::dummy>
915std::string type_name();
919 enable_if_t<classify_object<T>::value == object_category::container_value ||
920 classify_object<T>::value == object_category::wrapper_value,
921 detail::enabler> = detail::dummy>
922std::string type_name();
926 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value == 1,
927 detail::enabler> = detail::dummy>
928inline std::string type_name() {
929 return type_name<typename std::decay<typename std::tuple_element<0, T>::type>::type>();
933template <
typename T, std::
size_t I>
934inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_name() {
935 return std::string{};
939template <
typename T, std::
size_t I>
940inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_name() {
941 auto str = std::string{type_name<typename std::decay<typename std::tuple_element<I, T>::type>::type>()} +
',' +
942 tuple_name<T, I + 1>();
943 if(str.back() ==
',')
950 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value >= 2,
952inline std::string type_name() {
953 auto tname = std::string(1,
'[') + tuple_name<T, 0>();
954 tname.push_back(
']');
960 enable_if_t<classify_object<T>::value == object_category::container_value ||
961 classify_object<T>::value == object_category::wrapper_value,
963inline std::string type_name() {
964 return type_name<typename T::value_type>();
970template <typename T, enable_if_t<std::is_unsigned<T>::value, detail::enabler> = detail::dummy>
971bool integral_conversion(
const std::string &input, T &output)
noexcept {
977 const bool has_base_prefix = input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0 ||
978 input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0;
979 auto first_non_ws = input.find_first_not_of(
" \t\n\v\f\r", has_base_prefix ? 2 : 0);
980 if(first_non_ws != std::string::npos && input[first_non_ws] ==
'-') {
985 std::uint64_t output_ll = std::strtoull(input.c_str(), &val, 0);
986 if(errno == ERANGE) {
989 output =
static_cast<T
>(output_ll);
990 if(val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll) {
994 std::int64_t output_sll = std::strtoll(input.c_str(), &val, 0);
995 if(val == (input.c_str() + input.size())) {
996 output = (output_sll < 0) ? static_cast<T>(0) : static_cast<T>(output_sll);
997 return (
static_cast<std::int64_t
>(output) == output_sll);
1000 auto group_separators = get_group_separators();
1001 if(input.find_first_of(group_separators) != std::string::npos) {
1002 std::string nstring = input;
1003 for(
auto &separator : group_separators) {
1004 if(input.find_first_of(separator) != std::string::npos) {
1005 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1008 return integral_conversion(nstring, output);
1011 if(std::isspace(
static_cast<unsigned char>(input.back()))) {
1012 return integral_conversion(trim_copy(input), output);
1014 if(input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0) {
1017 output_ll = std::strtoull(input.c_str() + 2, &val, 8);
1018 if(errno == ERANGE) {
1021 output =
static_cast<T
>(output_ll);
1022 return (val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll);
1024 if(input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0) {
1030 output_ll = std::strtoull(input.c_str() + 2, &val, 2);
1031 if(errno == ERANGE) {
1034 output =
static_cast<T
>(output_ll);
1035 return (val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll);
1042template <typename T, enable_if_t<std::is_signed<T>::value, detail::enabler> = detail::dummy>
1043bool integral_conversion(
const std::string &input, T &output)
noexcept {
1047 char *val =
nullptr;
1049 std::int64_t output_ll = std::strtoll(input.c_str(), &val, 0);
1050 if(errno == ERANGE) {
1053 output =
static_cast<T
>(output_ll);
1054 if(val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll) {
1057 if(input ==
"true") {
1059 output =
static_cast<T
>(1);
1063 auto group_separators = get_group_separators();
1064 if(input.find_first_of(group_separators) != std::string::npos) {
1065 for(
auto &separator : group_separators) {
1066 if(input.find_first_of(separator) != std::string::npos) {
1067 std::string nstring = input;
1068 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1069 return integral_conversion(nstring, output);
1073 if(std::isspace(
static_cast<unsigned char>(input.back()))) {
1074 return integral_conversion(trim_copy(input), output);
1076 if(input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0) {
1079 output_ll = std::strtoll(input.c_str() + 2, &val, 8);
1080 if(errno == ERANGE) {
1083 output =
static_cast<T
>(output_ll);
1084 return (val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll);
1086 if(input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0) {
1092 output_ll = std::strtoll(input.c_str() + 2, &val, 2);
1093 if(errno == ERANGE) {
1096 output =
static_cast<T
>(output_ll);
1097 return (val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll);
1104CLI11_INLINE std::int64_t to_flag_value(std::string val)
noexcept;
1107template <
typename T,
1108 enable_if_t<classify_object<T>::value == object_category::integral_value ||
1109 classify_object<T>::value == object_category::unsigned_integral,
1110 detail::enabler> = detail::dummy>
1111bool lexical_cast(
const std::string &input, T &output) {
1112 return integral_conversion(input, output);
1116template <
typename T,
1117 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> = detail::dummy>
1118bool lexical_cast(
const std::string &input, T &output) {
1119 if(input.size() == 1) {
1120 output =
static_cast<T
>(input[0]);
1126 bool result = integral_conversion(input, res);
1128 output =
static_cast<T
>(res);
1134template <
typename T,
1135 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
1136bool lexical_cast(
const std::string &input, T &output) {
1138 auto out = to_flag_value(input);
1141 }
else if(errno == ERANGE) {
1142 output = (input[0] !=
'-');
1150template <
typename T,
1151 enable_if_t<classify_object<T>::value == object_category::floating_point, detail::enabler> = detail::dummy>
1152bool lexical_cast(
const std::string &input, T &output) {
1156 char *val =
nullptr;
1157 auto output_ld = std::strtold(input.c_str(), &val);
1160 if(val == input.c_str()) {
1163 output =
static_cast<T
>(output_ld);
1164 if(val == (input.c_str() + input.size())) {
1167 while(std::isspace(
static_cast<unsigned char>(*val))) {
1169 if(val == (input.c_str() + input.size())) {
1175 auto group_separators = get_group_separators();
1176 if(input.find_first_of(group_separators) != std::string::npos) {
1177 for(
auto &separator : group_separators) {
1178 if(input.find_first_of(separator) != std::string::npos) {
1179 std::string nstring = input;
1180 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1181 return lexical_cast(nstring, output);
1189template <
typename T,
1190 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
1191bool lexical_cast(
const std::string &input, T &output) {
1192 using XC =
typename wrapped_type<T, double>::type;
1195 bool worked =
false;
1196 auto nloc = str1.find_last_of(
"+-");
1197 if(nloc != std::string::npos && nloc > 0) {
1198 worked = lexical_cast(str1.substr(0, nloc), x);
1199 str1 = str1.substr(nloc);
1200 if(str1.back() ==
'i' || str1.back() ==
'j')
1202 worked = worked && lexical_cast(str1, y);
1204 if(str1.back() ==
'i' || str1.back() ==
'j') {
1206 worked = lexical_cast(str1, y);
1209 worked = lexical_cast(str1, x);
1217 return from_stream(input, output);
1221template <
typename T,
1222 enable_if_t<classify_object<T>::value == object_category::string_assignable, detail::enabler> = detail::dummy>
1223bool lexical_cast(
const std::string &input, T &output) {
1231 enable_if_t<classify_object<T>::value == object_category::string_constructible, detail::enabler> = detail::dummy>
1232bool lexical_cast(
const std::string &input, T &output) {
1240 enable_if_t<classify_object<T>::value == object_category::wstring_assignable, detail::enabler> = detail::dummy>
1241bool lexical_cast(
const std::string &input, T &output) {
1242 output = widen(input);
1248 enable_if_t<classify_object<T>::value == object_category::wstring_constructible, detail::enabler> = detail::dummy>
1249bool lexical_cast(
const std::string &input, T &output) {
1250 output = T{widen(input)};
1255template <
typename T,
1256 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
1257bool lexical_cast(
const std::string &input, T &output) {
1258 typename std::underlying_type<T>::type val;
1259 if(!integral_conversion(input, val)) {
1262 output =
static_cast<T
>(val);
1267template <
typename T,
1268 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1269 std::is_assignable<T &, typename T::value_type>::value,
1270 detail::enabler> = detail::dummy>
1271bool lexical_cast(
const std::string &input, T &output) {
1272 typename T::value_type val;
1273 if(lexical_cast(input, val)) {
1277 return from_stream(input, output);
1280template <
typename T,
1281 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1282 !std::is_assignable<T &, typename T::value_type>::value && std::is_assignable<T &, T>::value,
1283 detail::enabler> = detail::dummy>
1284bool lexical_cast(
const std::string &input, T &output) {
1285 typename T::value_type val;
1286 if(lexical_cast(input, val)) {
1290 return from_stream(input, output);
1296 enable_if_t<classify_object<T>::value == object_category::number_constructible, detail::enabler> = detail::dummy>
1297bool lexical_cast(
const std::string &input, T &output) {
1299 if(integral_conversion(input, val)) {
1305 if(lexical_cast(input, dval)) {
1310 return from_stream(input, output);
1316 enable_if_t<classify_object<T>::value == object_category::integer_constructible, detail::enabler> = detail::dummy>
1317bool lexical_cast(
const std::string &input, T &output) {
1319 if(integral_conversion(input, val)) {
1323 return from_stream(input, output);
1329 enable_if_t<classify_object<T>::value == object_category::double_constructible, detail::enabler> = detail::dummy>
1330bool lexical_cast(
const std::string &input, T &output) {
1332 if(lexical_cast(input, val)) {
1336 return from_stream(input, output);
1340template <
typename T,
1341 enable_if_t<classify_object<T>::value == object_category::other && std::is_assignable<T &, int>::value,
1342 detail::enabler> = detail::dummy>
1343bool lexical_cast(
const std::string &input, T &output) {
1345 if(integral_conversion(input, val)) {
1347#pragma warning(push)
1348#pragma warning(disable : 4800)
1361 return from_stream(input, output);
1366template <
typename T,
1367 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1368 is_istreamable<T>::value,
1369 detail::enabler> = detail::dummy>
1370bool lexical_cast(
const std::string &input, T &output) {
1371 return from_stream(input, output);
1376template <
typename T,
1377 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1378 !is_istreamable<T>::value && !adl_detail::is_lexical_castable<T>::value,
1379 detail::enabler> = detail::dummy>
1380bool lexical_cast(
const std::string & , T & ) {
1381 static_assert(!std::is_same<T, T>::value,
1382 "option object type must have a lexical cast overload or streaming input operator(>>) defined, if it "
1383 "is convertible from another type use the add_option<T, XC>(...) with XC being the known type");
1389template <
typename AssignTo,
1391 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !is_wrapper<AssignTo>::value &&
1392 (classify_object<AssignTo>::value == object_category::string_assignable ||
1393 classify_object<AssignTo>::value == object_category::string_constructible ||
1394 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1395 classify_object<AssignTo>::value == object_category::wstring_constructible),
1396 detail::enabler> = detail::dummy>
1397bool lexical_assign(
const std::string &input, AssignTo &output) {
1398 return lexical_cast(input, output);
1403template <
typename AssignTo,
1405 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && is_wrapper<AssignTo>::value &&
1406 (classify_object<AssignTo>::value == object_category::string_assignable ||
1407 classify_object<AssignTo>::value == object_category::string_constructible ||
1408 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1409 classify_object<AssignTo>::value == object_category::wstring_constructible),
1410 detail::enabler> = detail::dummy>
1411bool lexical_assign(
const std::string &input, AssignTo &output) {
1413 output = AssignTo{};
1416 return lexical_cast(input, output);
1420template <
typename AssignTo,
1422 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, AssignTo>::value &&
1423 classify_object<AssignTo>::value != object_category::string_assignable &&
1424 classify_object<AssignTo>::value != object_category::string_constructible &&
1425 classify_object<AssignTo>::value != object_category::wstring_assignable &&
1426 classify_object<AssignTo>::value != object_category::wstring_constructible,
1427 detail::enabler> = detail::dummy>
1428bool lexical_assign(
const std::string &input, AssignTo &output) {
1430 output = AssignTo{};
1434 return lexical_cast(input, output);
1438template <
typename AssignTo,
1440 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1441 classify_object<AssignTo>::value == object_category::wrapper_value,
1442 detail::enabler> = detail::dummy>
1443bool lexical_assign(
const std::string &input, AssignTo &output) {
1445 typename AssignTo::value_type emptyVal{};
1449 return lexical_cast(input, output);
1454template <
typename AssignTo,
1456 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1457 classify_object<AssignTo>::value != object_category::wrapper_value &&
1458 std::is_assignable<AssignTo &, int>::value,
1459 detail::enabler> = detail::dummy>
1460bool lexical_assign(
const std::string &input, AssignTo &output) {
1466 if(lexical_cast(input, val)) {
1467#if defined(__clang__)
1469#pragma clang diagnostic push
1470#pragma clang diagnostic ignored "-Wsign-conversion"
1471#elif defined(__GNUC__) && (__GNUC__ == 8)
1473#pragma GCC diagnostic push
1474#pragma GCC diagnostic ignored "-Wsign-conversion"
1477#if defined(__clang__)
1478#pragma clang diagnostic pop
1479#elif defined(__GNUC__) && (__GNUC__ == 8)
1480#pragma GCC diagnostic pop
1488template <
typename AssignTo,
1490 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, ConvertTo &>::value,
1491 detail::enabler> = detail::dummy>
1492bool lexical_assign(
const std::string &input, AssignTo &output) {
1494 bool parse_result = (!input.empty()) ? lexical_cast(input, val) : true;
1498 return parse_result;
1505 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, ConvertTo &>::value &&
1506 std::is_move_assignable<AssignTo>::value,
1507 detail::enabler> = detail::dummy>
1508bool lexical_assign(
const std::string &input, AssignTo &output) {
1510 bool parse_result = input.empty() ? true : lexical_cast(input, val);
1512 output = AssignTo(val);
1514 return parse_result;
1518template <
typename AssignTo,
1520 enable_if_t<classify_object<ConvertTo>::value <= object_category::other &&
1521 classify_object<AssignTo>::value <= object_category::wrapper_value,
1522 detail::enabler> = detail::dummy>
1523bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1524 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1529template <
typename AssignTo,
1531 enable_if_t<(type_count<AssignTo>::value <= 2) && expected_count<AssignTo>::value == 1 &&
1532 is_tuple_like<ConvertTo>::value && type_count_base<ConvertTo>::value == 2,
1533 detail::enabler> = detail::dummy>
1534bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1536 using FirstType =
typename std::remove_const<typename std::tuple_element<0, ConvertTo>::type>::type;
1537 using SecondType =
typename std::tuple_element<1, ConvertTo>::type;
1540 bool retval = lexical_assign<FirstType, FirstType>(strings[0], v1);
1541 retval = retval && lexical_assign<SecondType, SecondType>((strings.size() > 1) ? strings[1] : std::string{}, v2);
1543 output = AssignTo{v1, v2};
1549template <
class AssignTo,
1551 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1552 type_count<ConvertTo>::value == 1,
1553 detail::enabler> = detail::dummy>
1554bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1555 output.erase(output.begin(), output.end());
1556 if(strings.empty()) {
1559 if(strings.size() == 1 && strings[0] ==
"{}") {
1562 bool skip_remaining =
false;
1563 if(strings.size() == 2 && strings[0] ==
"{}" && is_separator(strings[1])) {
1564 skip_remaining =
true;
1566 for(
const auto &elem : strings) {
1567 typename AssignTo::value_type out;
1568 bool retval = lexical_assign<typename AssignTo::value_type, typename ConvertTo::value_type>(elem, out);
1572 output.insert(output.end(), std::move(out));
1573 if(skip_remaining) {
1577 return (!output.empty());
1581template <class AssignTo, class ConvertTo, enable_if_t<is_complex<ConvertTo>::value, detail::enabler> = detail::dummy>
1582bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1584 if(strings.size() >= 2 && !strings[1].empty()) {
1585 using XC2 =
typename wrapped_type<ConvertTo, double>::type;
1587 auto str1 = strings[1];
1588 if(str1.back() ==
'i' || str1.back() ==
'j') {
1591 auto worked = lexical_cast(strings[0], x) && lexical_cast(str1, y);
1593 output = ConvertTo{x, y};
1597 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1601template <
class AssignTo,
1603 enable_if_t<is_mutable_container<AssignTo>::value && (expected_count<ConvertTo>::value == 1) &&
1604 (type_count<ConvertTo>::value == 1),
1605 detail::enabler> = detail::dummy>
1606bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1609 output.reserve(strings.size());
1610 for(
const auto &elem : strings) {
1612 output.emplace_back();
1613 retval = retval && lexical_assign<typename AssignTo::value_type, ConvertTo>(elem, output.back());
1615 return (!output.empty()) && retval;
1621template <
class AssignTo,
1623 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1624 type_count_base<ConvertTo>::value == 2,
1625 detail::enabler> = detail::dummy>
1626bool lexical_conversion(std::vector<std::string> strings, AssignTo &output);
1629template <
class AssignTo,
1631 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1632 type_count_base<ConvertTo>::value != 2 &&
1633 ((type_count<ConvertTo>::value > 2) ||
1634 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1635 detail::enabler> = detail::dummy>
1636bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1639template <
class AssignTo,
1641 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1642 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1643 type_count<ConvertTo>::value > 2),
1644 detail::enabler> = detail::dummy>
1645bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1649template <
typename AssignTo,
1651 enable_if_t<!is_tuple_like<AssignTo>::value && !is_mutable_container<AssignTo>::value &&
1652 classify_object<ConvertTo>::value != object_category::wrapper_value &&
1653 (is_mutable_container<ConvertTo>::value || type_count<ConvertTo>::value > 2),
1654 detail::enabler> = detail::dummy>
1655bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1657 if(strings.size() > 1 || (!strings.empty() && !(strings.front().empty()))) {
1659 auto retval = lexical_conversion<ConvertTo, ConvertTo>(strings, val);
1660 output = AssignTo{val};
1663 output = AssignTo{};
1668template <
class AssignTo,
class ConvertTo, std::
size_t I>
1669inline typename std::enable_if<(I >= type_count_base<AssignTo>::value),
bool>::type
1670tuple_conversion(
const std::vector<std::string> &, AssignTo &) {
1675template <
class AssignTo,
class ConvertTo>
1676inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && type_count<ConvertTo>::value == 1,
bool>::type
1677tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1678 auto retval = lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1679 strings.erase(strings.begin());
1684template <
class AssignTo,
class ConvertTo>
1685inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && (type_count<ConvertTo>::value > 1) &&
1686 type_count<ConvertTo>::value == type_count_min<ConvertTo>::value,
1688tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1689 auto retval = lexical_conversion<AssignTo, ConvertTo>(strings, output);
1690 strings.erase(strings.begin(), strings.begin() + type_count<ConvertTo>::value);
1695template <
class AssignTo,
class ConvertTo>
1696inline typename std::enable_if<is_mutable_container<ConvertTo>::value ||
1697 type_count<ConvertTo>::value != type_count_min<ConvertTo>::value,
1699tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1701 std::size_t index{subtype_count_min<ConvertTo>::value};
1702 const std::size_t mx_count{subtype_count<ConvertTo>::value};
1703 const std::size_t mx{(std::min)(mx_count, strings.size() - 1)};
1706 if(is_separator(strings[index])) {
1711 bool retval = lexical_conversion<AssignTo, ConvertTo>(
1712 std::vector<std::string>(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index)), output);
1713 if(strings.size() > index) {
1714 strings.erase(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index) + 1);
1722template <
class AssignTo,
class ConvertTo, std::
size_t I>
1723inline typename std::enable_if<(I < type_count_base<AssignTo>::value),
bool>::type
1724tuple_conversion(std::vector<std::string> strings, AssignTo &output) {
1726 using ConvertToElement =
typename std::
1727 conditional<is_tuple_like<ConvertTo>::value,
typename std::tuple_element<I, ConvertTo>::type, ConvertTo>::type;
1728 if(!strings.empty()) {
1729 retval = retval && tuple_type_conversion<typename std::tuple_element<I, AssignTo>::type, ConvertToElement>(
1730 strings, std::get<I>(output));
1732 retval = retval && tuple_conversion<AssignTo, ConvertTo, I + 1>(std::move(strings), output);
1737template <
class AssignTo,
1739 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1740 type_count_base<ConvertTo>::value == 2,
1742bool lexical_conversion(std::vector<std::string> strings, AssignTo &output) {
1744 while(!strings.empty()) {
1746 typename std::remove_const<typename std::tuple_element<0, typename ConvertTo::value_type>::type>::type v1{};
1747 typename std::tuple_element<1, typename ConvertTo::value_type>::type v2{};
1748 bool retval = tuple_type_conversion<decltype(v1), decltype(v1)>(strings, v1);
1749 if(!strings.empty()) {
1750 retval = retval && tuple_type_conversion<decltype(v2), decltype(v2)>(strings, v2);
1756 output.insert(output.end(),
typename AssignTo::value_type{v1, v2});
1761 return (!output.empty());
1765template <
class AssignTo,
1767 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1768 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1769 type_count<ConvertTo>::value > 2),
1771bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1773 !is_tuple_like<ConvertTo>::value || type_count_base<AssignTo>::value == type_count_base<ConvertTo>::value,
1774 "if the conversion type is defined as a tuple it must be the same size as the type you are converting to");
1775 return tuple_conversion<AssignTo, ConvertTo, 0>(strings, output);
1779template <
class AssignTo,
1781 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1782 type_count_base<ConvertTo>::value != 2 &&
1783 ((type_count<ConvertTo>::value > 2) ||
1784 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1786bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1789 std::vector<std::string> temp;
1791 std::size_t icount{0};
1792 std::size_t xcm{type_count<ConvertTo>::value};
1793 auto ii_max = strings.size();
1794 while(ii < ii_max) {
1795 temp.push_back(strings[ii]);
1798 if(icount == xcm || is_separator(temp.back()) || ii == ii_max) {
1799 if(
static_cast<int>(xcm) > type_count_min<ConvertTo>::value && is_separator(temp.back())) {
1802 typename AssignTo::value_type temp_out;
1804 lexical_conversion<typename AssignTo::value_type, typename ConvertTo::value_type>(temp, temp_out);
1809 output.insert(output.end(), std::move(temp_out));
1817template <
typename AssignTo,
1819 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1820 std::is_assignable<ConvertTo &, ConvertTo>::value,
1821 detail::enabler> = detail::dummy>
1822bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1823 if(strings.empty() || strings.front().empty()) {
1824 output = ConvertTo{};
1827 typename ConvertTo::value_type val;
1828 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1829 output = ConvertTo{val};
1836template <
typename AssignTo,
1838 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1839 !std::is_assignable<AssignTo &, ConvertTo>::value,
1840 detail::enabler> = detail::dummy>
1841bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1842 using ConvertType =
typename ConvertTo::value_type;
1843 if(strings.empty() || strings.front().empty()) {
1844 output = ConvertType{};
1848 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1856CLI11_INLINE std::string sum_string_vector(
const std::vector<std::string> &values);
1862#ifndef CLI11_COMPILE
1863#include "impl/TypeTools_inl.hpp"
Definition TypeTools.hpp:102
Check for complex.
Definition TypeTools.hpp:241
Definition TypeTools.hpp:183
Check for input streamability.
Definition TypeTools.hpp:230
Definition TypeTools.hpp:219
Definition TypeTools.hpp:305
This can be specialized to override the type deduction for IsMember.
Definition TypeTools.hpp:87
not a pointer
Definition TypeTools.hpp:121
Definition TypeTools.hpp:131
Definition TypeTools.hpp:266
Definition TypeTools.hpp:286
Definition TypeTools.hpp:297
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:163
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:167
Adaptor for set-like structure: This just wraps a normal container in a few utilities that do almost ...
Definition TypeTools.hpp:136
static auto second(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the second value (really just the underlying value).
Definition TypeTools.hpp:146
static auto first(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the first value (really just the underlying value).
Definition TypeTools.hpp:142
forward declare the subtype_count_min structure
Definition TypeTools.hpp:526
Set of overloads to get the type size of an object.
Definition TypeTools.hpp:523
This will only trigger for actual void type.
Definition TypeTools.hpp:317
This will only trigger for actual void type.
Definition TypeTools.hpp:529
template to get the underlying value type if it exists or use a default
Definition TypeTools.hpp:511
Check to see if something is bool (fail check by default).
Definition TypeTools.hpp:67
Check to see if something is copyable pointer.
Definition TypeTools.hpp:82
Check to see if something is a shared pointer.
Definition TypeTools.hpp:73
A copy of std::void_t from C++17 (helper for C++11 and C++14).
Definition TypeTools.hpp:56