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 auto first_non_ws = input.find_first_not_of(
" \t\n\v\f\r");
978 if(first_non_ws != std::string::npos && input[first_non_ws] ==
'-') {
983 std::uint64_t output_ll = std::strtoull(input.c_str(), &val, 0);
984 if(errno == ERANGE) {
987 output =
static_cast<T
>(output_ll);
988 if(val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll) {
992 std::int64_t output_sll = std::strtoll(input.c_str(), &val, 0);
993 if(val == (input.c_str() + input.size())) {
994 output = (output_sll < 0) ? static_cast<T>(0) : static_cast<T>(output_sll);
995 return (
static_cast<std::int64_t
>(output) == output_sll);
998 auto group_separators = get_group_separators();
999 if(input.find_first_of(group_separators) != std::string::npos) {
1000 std::string nstring = input;
1001 for(
auto &separator : group_separators) {
1002 if(input.find_first_of(separator) != std::string::npos) {
1003 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1006 return integral_conversion(nstring, output);
1009 if(std::isspace(
static_cast<unsigned char>(input.back()))) {
1010 return integral_conversion(trim_copy(input), output);
1012 if(input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0) {
1015 output_ll = std::strtoull(input.c_str() + 2, &val, 8);
1016 if(errno == ERANGE) {
1019 output =
static_cast<T
>(output_ll);
1020 return (val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll);
1022 if(input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0) {
1028 output_ll = std::strtoull(input.c_str() + 2, &val, 2);
1029 if(errno == ERANGE) {
1032 output =
static_cast<T
>(output_ll);
1033 return (val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll);
1040template <typename T, enable_if_t<std::is_signed<T>::value, detail::enabler> = detail::dummy>
1041bool integral_conversion(
const std::string &input, T &output)
noexcept {
1045 char *val =
nullptr;
1047 std::int64_t output_ll = std::strtoll(input.c_str(), &val, 0);
1048 if(errno == ERANGE) {
1051 output =
static_cast<T
>(output_ll);
1052 if(val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll) {
1055 if(input ==
"true") {
1057 output =
static_cast<T
>(1);
1061 auto group_separators = get_group_separators();
1062 if(input.find_first_of(group_separators) != std::string::npos) {
1063 for(
auto &separator : group_separators) {
1064 if(input.find_first_of(separator) != std::string::npos) {
1065 std::string nstring = input;
1066 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1067 return integral_conversion(nstring, output);
1071 if(std::isspace(
static_cast<unsigned char>(input.back()))) {
1072 return integral_conversion(trim_copy(input), output);
1074 if(input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0) {
1077 output_ll = std::strtoll(input.c_str() + 2, &val, 8);
1078 if(errno == ERANGE) {
1081 output =
static_cast<T
>(output_ll);
1082 return (val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll);
1084 if(input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0) {
1090 output_ll = std::strtoll(input.c_str() + 2, &val, 2);
1091 if(errno == ERANGE) {
1094 output =
static_cast<T
>(output_ll);
1095 return (val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll);
1102CLI11_INLINE std::int64_t to_flag_value(std::string val)
noexcept;
1105template <
typename T,
1106 enable_if_t<classify_object<T>::value == object_category::integral_value ||
1107 classify_object<T>::value == object_category::unsigned_integral,
1108 detail::enabler> = detail::dummy>
1109bool lexical_cast(
const std::string &input, T &output) {
1110 return integral_conversion(input, output);
1114template <
typename T,
1115 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> = detail::dummy>
1116bool lexical_cast(
const std::string &input, T &output) {
1117 if(input.size() == 1) {
1118 output =
static_cast<T
>(input[0]);
1124 bool result = integral_conversion(input, res);
1126 output =
static_cast<T
>(res);
1132template <
typename T,
1133 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
1134bool lexical_cast(
const std::string &input, T &output) {
1136 auto out = to_flag_value(input);
1139 }
else if(errno == ERANGE) {
1140 output = (input[0] !=
'-');
1148template <
typename T,
1149 enable_if_t<classify_object<T>::value == object_category::floating_point, detail::enabler> = detail::dummy>
1150bool lexical_cast(
const std::string &input, T &output) {
1154 char *val =
nullptr;
1155 auto output_ld = std::strtold(input.c_str(), &val);
1158 if(val == input.c_str()) {
1161 output =
static_cast<T
>(output_ld);
1162 if(val == (input.c_str() + input.size())) {
1165 while(std::isspace(
static_cast<unsigned char>(*val))) {
1167 if(val == (input.c_str() + input.size())) {
1173 auto group_separators = get_group_separators();
1174 if(input.find_first_of(group_separators) != std::string::npos) {
1175 for(
auto &separator : group_separators) {
1176 if(input.find_first_of(separator) != std::string::npos) {
1177 std::string nstring = input;
1178 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1179 return lexical_cast(nstring, output);
1187template <
typename T,
1188 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
1189bool lexical_cast(
const std::string &input, T &output) {
1190 using XC =
typename wrapped_type<T, double>::type;
1193 bool worked =
false;
1194 auto nloc = str1.find_last_of(
"+-");
1195 if(nloc != std::string::npos && nloc > 0) {
1196 worked = lexical_cast(str1.substr(0, nloc), x);
1197 str1 = str1.substr(nloc);
1198 if(str1.back() ==
'i' || str1.back() ==
'j')
1200 worked = worked && lexical_cast(str1, y);
1202 if(str1.back() ==
'i' || str1.back() ==
'j') {
1204 worked = lexical_cast(str1, y);
1207 worked = lexical_cast(str1, x);
1215 return from_stream(input, output);
1219template <
typename T,
1220 enable_if_t<classify_object<T>::value == object_category::string_assignable, detail::enabler> = detail::dummy>
1221bool lexical_cast(
const std::string &input, T &output) {
1229 enable_if_t<classify_object<T>::value == object_category::string_constructible, detail::enabler> = detail::dummy>
1230bool lexical_cast(
const std::string &input, T &output) {
1238 enable_if_t<classify_object<T>::value == object_category::wstring_assignable, detail::enabler> = detail::dummy>
1239bool lexical_cast(
const std::string &input, T &output) {
1240 output = widen(input);
1246 enable_if_t<classify_object<T>::value == object_category::wstring_constructible, detail::enabler> = detail::dummy>
1247bool lexical_cast(
const std::string &input, T &output) {
1248 output = T{widen(input)};
1253template <
typename T,
1254 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
1255bool lexical_cast(
const std::string &input, T &output) {
1256 typename std::underlying_type<T>::type val;
1257 if(!integral_conversion(input, val)) {
1260 output =
static_cast<T
>(val);
1265template <
typename T,
1266 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1267 std::is_assignable<T &, typename T::value_type>::value,
1268 detail::enabler> = detail::dummy>
1269bool lexical_cast(
const std::string &input, T &output) {
1270 typename T::value_type val;
1271 if(lexical_cast(input, val)) {
1275 return from_stream(input, output);
1278template <
typename T,
1279 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1280 !std::is_assignable<T &, typename T::value_type>::value && std::is_assignable<T &, T>::value,
1281 detail::enabler> = detail::dummy>
1282bool lexical_cast(
const std::string &input, T &output) {
1283 typename T::value_type val;
1284 if(lexical_cast(input, val)) {
1288 return from_stream(input, output);
1294 enable_if_t<classify_object<T>::value == object_category::number_constructible, detail::enabler> = detail::dummy>
1295bool lexical_cast(
const std::string &input, T &output) {
1297 if(integral_conversion(input, val)) {
1303 if(lexical_cast(input, dval)) {
1308 return from_stream(input, output);
1314 enable_if_t<classify_object<T>::value == object_category::integer_constructible, detail::enabler> = detail::dummy>
1315bool lexical_cast(
const std::string &input, T &output) {
1317 if(integral_conversion(input, val)) {
1321 return from_stream(input, output);
1327 enable_if_t<classify_object<T>::value == object_category::double_constructible, detail::enabler> = detail::dummy>
1328bool lexical_cast(
const std::string &input, T &output) {
1330 if(lexical_cast(input, val)) {
1334 return from_stream(input, output);
1338template <
typename T,
1339 enable_if_t<classify_object<T>::value == object_category::other && std::is_assignable<T &, int>::value,
1340 detail::enabler> = detail::dummy>
1341bool lexical_cast(
const std::string &input, T &output) {
1343 if(integral_conversion(input, val)) {
1345#pragma warning(push)
1346#pragma warning(disable : 4800)
1359 return from_stream(input, output);
1364template <
typename T,
1365 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1366 is_istreamable<T>::value,
1367 detail::enabler> = detail::dummy>
1368bool lexical_cast(
const std::string &input, T &output) {
1369 return from_stream(input, output);
1374template <
typename T,
1375 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1376 !is_istreamable<T>::value && !adl_detail::is_lexical_castable<T>::value,
1377 detail::enabler> = detail::dummy>
1378bool lexical_cast(
const std::string & , T & ) {
1379 static_assert(!std::is_same<T, T>::value,
1380 "option object type must have a lexical cast overload or streaming input operator(>>) defined, if it "
1381 "is convertible from another type use the add_option<T, XC>(...) with XC being the known type");
1387template <
typename AssignTo,
1389 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !is_wrapper<AssignTo>::value &&
1390 (classify_object<AssignTo>::value == object_category::string_assignable ||
1391 classify_object<AssignTo>::value == object_category::string_constructible ||
1392 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1393 classify_object<AssignTo>::value == object_category::wstring_constructible),
1394 detail::enabler> = detail::dummy>
1395bool lexical_assign(
const std::string &input, AssignTo &output) {
1396 return lexical_cast(input, output);
1401template <
typename AssignTo,
1403 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && is_wrapper<AssignTo>::value &&
1404 (classify_object<AssignTo>::value == object_category::string_assignable ||
1405 classify_object<AssignTo>::value == object_category::string_constructible ||
1406 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1407 classify_object<AssignTo>::value == object_category::wstring_constructible),
1408 detail::enabler> = detail::dummy>
1409bool lexical_assign(
const std::string &input, AssignTo &output) {
1411 output = AssignTo{};
1414 return lexical_cast(input, output);
1418template <
typename AssignTo,
1420 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, AssignTo>::value &&
1421 classify_object<AssignTo>::value != object_category::string_assignable &&
1422 classify_object<AssignTo>::value != object_category::string_constructible &&
1423 classify_object<AssignTo>::value != object_category::wstring_assignable &&
1424 classify_object<AssignTo>::value != object_category::wstring_constructible,
1425 detail::enabler> = detail::dummy>
1426bool lexical_assign(
const std::string &input, AssignTo &output) {
1428 output = AssignTo{};
1432 return lexical_cast(input, output);
1436template <
typename AssignTo,
1438 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1439 classify_object<AssignTo>::value == object_category::wrapper_value,
1440 detail::enabler> = detail::dummy>
1441bool lexical_assign(
const std::string &input, AssignTo &output) {
1443 typename AssignTo::value_type emptyVal{};
1447 return lexical_cast(input, output);
1452template <
typename AssignTo,
1454 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1455 classify_object<AssignTo>::value != object_category::wrapper_value &&
1456 std::is_assignable<AssignTo &, int>::value,
1457 detail::enabler> = detail::dummy>
1458bool lexical_assign(
const std::string &input, AssignTo &output) {
1464 if(lexical_cast(input, val)) {
1465#if defined(__clang__)
1467#pragma clang diagnostic push
1468#pragma clang diagnostic ignored "-Wsign-conversion"
1469#elif defined(__GNUC__) && (__GNUC__ == 8)
1471#pragma GCC diagnostic push
1472#pragma GCC diagnostic ignored "-Wsign-conversion"
1475#if defined(__clang__)
1476#pragma clang diagnostic pop
1477#elif defined(__GNUC__) && (__GNUC__ == 8)
1478#pragma GCC diagnostic pop
1486template <
typename AssignTo,
1488 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, ConvertTo &>::value,
1489 detail::enabler> = detail::dummy>
1490bool lexical_assign(
const std::string &input, AssignTo &output) {
1492 bool parse_result = (!input.empty()) ? lexical_cast(input, val) : true;
1496 return parse_result;
1503 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, ConvertTo &>::value &&
1504 std::is_move_assignable<AssignTo>::value,
1505 detail::enabler> = detail::dummy>
1506bool lexical_assign(
const std::string &input, AssignTo &output) {
1508 bool parse_result = input.empty() ? true : lexical_cast(input, val);
1510 output = AssignTo(val);
1512 return parse_result;
1516template <
typename AssignTo,
1518 enable_if_t<classify_object<ConvertTo>::value <= object_category::other &&
1519 classify_object<AssignTo>::value <= object_category::wrapper_value,
1520 detail::enabler> = detail::dummy>
1521bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1522 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1527template <
typename AssignTo,
1529 enable_if_t<(type_count<AssignTo>::value <= 2) && expected_count<AssignTo>::value == 1 &&
1530 is_tuple_like<ConvertTo>::value && type_count_base<ConvertTo>::value == 2,
1531 detail::enabler> = detail::dummy>
1532bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1534 using FirstType =
typename std::remove_const<typename std::tuple_element<0, ConvertTo>::type>::type;
1535 using SecondType =
typename std::tuple_element<1, ConvertTo>::type;
1538 bool retval = lexical_assign<FirstType, FirstType>(strings[0], v1);
1539 retval = retval && lexical_assign<SecondType, SecondType>((strings.size() > 1) ? strings[1] : std::string{}, v2);
1541 output = AssignTo{v1, v2};
1547template <
class AssignTo,
1549 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1550 type_count<ConvertTo>::value == 1,
1551 detail::enabler> = detail::dummy>
1552bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1553 output.erase(output.begin(), output.end());
1554 if(strings.empty()) {
1557 if(strings.size() == 1 && strings[0] ==
"{}") {
1560 bool skip_remaining =
false;
1561 if(strings.size() == 2 && strings[0] ==
"{}" && is_separator(strings[1])) {
1562 skip_remaining =
true;
1564 for(
const auto &elem : strings) {
1565 typename AssignTo::value_type out;
1566 bool retval = lexical_assign<typename AssignTo::value_type, typename ConvertTo::value_type>(elem, out);
1570 output.insert(output.end(), std::move(out));
1571 if(skip_remaining) {
1575 return (!output.empty());
1579template <class AssignTo, class ConvertTo, enable_if_t<is_complex<ConvertTo>::value, detail::enabler> = detail::dummy>
1580bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1582 if(strings.size() >= 2 && !strings[1].empty()) {
1583 using XC2 =
typename wrapped_type<ConvertTo, double>::type;
1585 auto str1 = strings[1];
1586 if(str1.back() ==
'i' || str1.back() ==
'j') {
1589 auto worked = lexical_cast(strings[0], x) && lexical_cast(str1, y);
1591 output = ConvertTo{x, y};
1595 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1599template <
class AssignTo,
1601 enable_if_t<is_mutable_container<AssignTo>::value && (expected_count<ConvertTo>::value == 1) &&
1602 (type_count<ConvertTo>::value == 1),
1603 detail::enabler> = detail::dummy>
1604bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1607 output.reserve(strings.size());
1608 for(
const auto &elem : strings) {
1610 output.emplace_back();
1611 retval = retval && lexical_assign<typename AssignTo::value_type, ConvertTo>(elem, output.back());
1613 return (!output.empty()) && retval;
1619template <
class AssignTo,
1621 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1622 type_count_base<ConvertTo>::value == 2,
1623 detail::enabler> = detail::dummy>
1624bool lexical_conversion(std::vector<std::string> strings, AssignTo &output);
1627template <
class AssignTo,
1629 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1630 type_count_base<ConvertTo>::value != 2 &&
1631 ((type_count<ConvertTo>::value > 2) ||
1632 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1633 detail::enabler> = detail::dummy>
1634bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1637template <
class AssignTo,
1639 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1640 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1641 type_count<ConvertTo>::value > 2),
1642 detail::enabler> = detail::dummy>
1643bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1647template <
typename AssignTo,
1649 enable_if_t<!is_tuple_like<AssignTo>::value && !is_mutable_container<AssignTo>::value &&
1650 classify_object<ConvertTo>::value != object_category::wrapper_value &&
1651 (is_mutable_container<ConvertTo>::value || type_count<ConvertTo>::value > 2),
1652 detail::enabler> = detail::dummy>
1653bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1655 if(strings.size() > 1 || (!strings.empty() && !(strings.front().empty()))) {
1657 auto retval = lexical_conversion<ConvertTo, ConvertTo>(strings, val);
1658 output = AssignTo{val};
1661 output = AssignTo{};
1666template <
class AssignTo,
class ConvertTo, std::
size_t I>
1667inline typename std::enable_if<(I >= type_count_base<AssignTo>::value),
bool>::type
1668tuple_conversion(
const std::vector<std::string> &, AssignTo &) {
1673template <
class AssignTo,
class ConvertTo>
1674inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && type_count<ConvertTo>::value == 1,
bool>::type
1675tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1676 auto retval = lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1677 strings.erase(strings.begin());
1682template <
class AssignTo,
class ConvertTo>
1683inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && (type_count<ConvertTo>::value > 1) &&
1684 type_count<ConvertTo>::value == type_count_min<ConvertTo>::value,
1686tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1687 auto retval = lexical_conversion<AssignTo, ConvertTo>(strings, output);
1688 strings.erase(strings.begin(), strings.begin() + type_count<ConvertTo>::value);
1693template <
class AssignTo,
class ConvertTo>
1694inline typename std::enable_if<is_mutable_container<ConvertTo>::value ||
1695 type_count<ConvertTo>::value != type_count_min<ConvertTo>::value,
1697tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1699 std::size_t index{subtype_count_min<ConvertTo>::value};
1700 const std::size_t mx_count{subtype_count<ConvertTo>::value};
1701 const std::size_t mx{(std::min)(mx_count, strings.size() - 1)};
1704 if(is_separator(strings[index])) {
1709 bool retval = lexical_conversion<AssignTo, ConvertTo>(
1710 std::vector<std::string>(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index)), output);
1711 if(strings.size() > index) {
1712 strings.erase(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index) + 1);
1720template <
class AssignTo,
class ConvertTo, std::
size_t I>
1721inline typename std::enable_if<(I < type_count_base<AssignTo>::value),
bool>::type
1722tuple_conversion(std::vector<std::string> strings, AssignTo &output) {
1724 using ConvertToElement =
typename std::
1725 conditional<is_tuple_like<ConvertTo>::value,
typename std::tuple_element<I, ConvertTo>::type, ConvertTo>::type;
1726 if(!strings.empty()) {
1727 retval = retval && tuple_type_conversion<typename std::tuple_element<I, AssignTo>::type, ConvertToElement>(
1728 strings, std::get<I>(output));
1730 retval = retval && tuple_conversion<AssignTo, ConvertTo, I + 1>(std::move(strings), output);
1735template <
class AssignTo,
1737 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1738 type_count_base<ConvertTo>::value == 2,
1740bool lexical_conversion(std::vector<std::string> strings, AssignTo &output) {
1742 while(!strings.empty()) {
1744 typename std::remove_const<typename std::tuple_element<0, typename ConvertTo::value_type>::type>::type v1{};
1745 typename std::tuple_element<1, typename ConvertTo::value_type>::type v2{};
1746 bool retval = tuple_type_conversion<decltype(v1), decltype(v1)>(strings, v1);
1747 if(!strings.empty()) {
1748 retval = retval && tuple_type_conversion<decltype(v2), decltype(v2)>(strings, v2);
1754 output.insert(output.end(),
typename AssignTo::value_type{v1, v2});
1759 return (!output.empty());
1763template <
class AssignTo,
1765 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1766 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1767 type_count<ConvertTo>::value > 2),
1769bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1771 !is_tuple_like<ConvertTo>::value || type_count_base<AssignTo>::value == type_count_base<ConvertTo>::value,
1772 "if the conversion type is defined as a tuple it must be the same size as the type you are converting to");
1773 return tuple_conversion<AssignTo, ConvertTo, 0>(strings, output);
1777template <
class AssignTo,
1779 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1780 type_count_base<ConvertTo>::value != 2 &&
1781 ((type_count<ConvertTo>::value > 2) ||
1782 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1784bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1787 std::vector<std::string> temp;
1789 std::size_t icount{0};
1790 std::size_t xcm{type_count<ConvertTo>::value};
1791 auto ii_max = strings.size();
1792 while(ii < ii_max) {
1793 temp.push_back(strings[ii]);
1796 if(icount == xcm || is_separator(temp.back()) || ii == ii_max) {
1797 if(
static_cast<int>(xcm) > type_count_min<ConvertTo>::value && is_separator(temp.back())) {
1800 typename AssignTo::value_type temp_out;
1802 lexical_conversion<typename AssignTo::value_type, typename ConvertTo::value_type>(temp, temp_out);
1807 output.insert(output.end(), std::move(temp_out));
1815template <
typename AssignTo,
1817 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1818 std::is_assignable<ConvertTo &, ConvertTo>::value,
1819 detail::enabler> = detail::dummy>
1820bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1821 if(strings.empty() || strings.front().empty()) {
1822 output = ConvertTo{};
1825 typename ConvertTo::value_type val;
1826 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1827 output = ConvertTo{val};
1834template <
typename AssignTo,
1836 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1837 !std::is_assignable<AssignTo &, ConvertTo>::value,
1838 detail::enabler> = detail::dummy>
1839bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1840 using ConvertType =
typename ConvertTo::value_type;
1841 if(strings.empty() || strings.front().empty()) {
1842 output = ConvertType{};
1846 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1854CLI11_INLINE std::string sum_string_vector(
const std::vector<std::string> &values);
1860#ifndef CLI11_COMPILE
1861#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