30#include "Encoding.hpp"
32#include "StringTools.hpp"
43enum class enabler : std::uint8_t {};
46CLI11_MODULE_INLINE
constexpr enabler dummy = {};
54template <
bool B,
class T =
void>
using enable_if_t =
typename std::enable_if<B, T>::type;
62template <
typename... Ts>
using void_t =
typename make_void<Ts...>::type;
65template <
bool B,
class T,
class F>
using conditional_t =
typename std::conditional<B, T, F>::type;
68template <
typename T>
struct is_bool : std::false_type {};
71template <>
struct is_bool<bool> : std::true_type {};
77template <
typename T>
struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
80template <
typename T>
struct is_shared_ptr<const std::shared_ptr<T>> : std::true_type {};
94 using type = std::string;
104 template <
typename TT,
typename SS>
105 static auto test(
int) ->
decltype(lexical_cast(std::declval<const SS &>(), std::declval<TT &>()), std::true_type());
107 template <
typename,
typename>
static auto test(...) -> std::false_type;
110 static constexpr bool value =
decltype(test<T, S>(0))::value;
126template <
typename T>
struct element_type<T, typename std::enable_if<is_copyable_ptr<T>::value>::type> {
127 using type =
typename std::pointer_traits<T>::element_type;
137template <
typename T,
typename _ =
void>
struct pair_adaptor : std::false_type {
138 using value_type =
typename T::value_type;
139 using first_type =
typename std::remove_const<value_type>::type;
140 using second_type =
typename std::remove_const<value_type>::type;
143 template <
typename Q>
static auto first(Q &&pair_value) ->
decltype(std::forward<Q>(pair_value)) {
144 return std::forward<Q>(pair_value);
147 template <
typename Q>
static auto second(Q &&pair_value) ->
decltype(std::forward<Q>(pair_value)) {
148 return std::forward<Q>(pair_value);
157 conditional_t<false, void_t<typename T::value_type::first_type, typename T::value_type::second_type>, void>>
159 using value_type =
typename T::value_type;
160 using first_type =
typename std::remove_const<typename value_type::first_type>::type;
161 using second_type =
typename std::remove_const<typename value_type::second_type>::type;
164 template <
typename Q>
static auto first(Q &&pair_value) ->
decltype(std::get<0>(std::forward<Q>(pair_value))) {
165 return std::get<0>(std::forward<Q>(pair_value));
168 template <
typename Q>
static auto second(Q &&pair_value) ->
decltype(std::get<1>(std::forward<Q>(pair_value))) {
169 return std::get<1>(std::forward<Q>(pair_value));
180#pragma GCC diagnostic push
181#pragma GCC diagnostic ignored "-Wnarrowing"
185 template <
typename TT,
typename CC>
186 static auto test(
int, std::true_type) ->
decltype(
189#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
190#pragma nv_diag_suppress 2361
192#pragma diag_suppress 2361
195 TT{std::declval<CC>()}
197#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
198#pragma nv_diag_default 2361
200#pragma diag_default 2361
204 std::is_move_assignable<TT>());
206 template <
typename TT,
typename CC>
static auto test(
int, std::false_type) -> std::false_type;
208 template <
typename,
typename>
static auto test(...) -> std::false_type;
211 static constexpr bool value =
decltype(test<T, C>(0,
typename std::is_constructible<T, C>::type()))::value;
214#pragma GCC diagnostic pop
221 template <
typename TT,
typename SS>
222 static auto test(
int) ->
decltype(std::declval<SS &>() << std::declval<TT>(), std::true_type());
224 template <
typename,
typename>
static auto test(...) -> std::false_type;
227 static constexpr bool value =
decltype(test<T, S>(0))::value;
232 template <
typename TT,
typename SS>
233 static auto test(
int) ->
decltype(std::declval<SS &>() >> std::declval<TT &>(), std::true_type());
235 template <
typename,
typename>
static auto test(...) -> std::false_type;
238 static constexpr bool value =
decltype(test<T, S>(0))::value;
243 template <
typename TT>
244 static auto test(
int) ->
decltype(std::declval<TT>().real(), std::declval<TT>().imag(), std::true_type());
246 template <
typename>
static auto test(...) -> std::false_type;
249 static constexpr bool value =
decltype(test<T>(0))::value;
253template <typename T, enable_if_t<is_istreamable<T>::value, detail::enabler> = detail::dummy>
254bool from_stream(
const std::string &istring, T &obj) {
255 std::istringstream is;
258 return !is.fail() && !is.rdbuf()->in_avail();
261template <typename T, enable_if_t<!is_istreamable<T>::value, detail::enabler> = detail::dummy>
262bool from_stream(
const std::string & , T & ) {
276 void_t<typename T::value_type,
277 decltype(std::declval<T>().end()),
278 decltype(std::declval<T>().clear()),
279 decltype(std::declval<T>().insert(std::declval<decltype(std::declval<T>().end())>(),
280 std::declval<const typename T::value_type &>()))>,
281 void>> :
public conditional_t<std::is_constructible<T, std::string>::value ||
282 std::is_constructible<T, std::wstring>::value,
294 conditional_t<false, void_t<decltype(std::declval<T>().end()), decltype(std::declval<T>().begin())>, void>>
295 :
public std::true_type {};
298template <
typename T,
typename _ =
void>
struct is_wrapper : std::false_type {};
302struct is_wrapper<T, conditional_t<false, void_t<typename T::value_type>, void>> :
public std::true_type {};
307 template <typename SS, enable_if_t<!is_complex<SS>::value, detail::enabler> = detail::dummy>
310 static auto test(
int) ->
decltype(std::tuple_size<typename std::decay<SS>::type>::value, std::true_type{});
311 template <
typename>
static auto test(...) -> std::false_type;
314 static constexpr bool value =
decltype(test<S>(0))::value;
319 static const int value{0};
325 typename std::enable_if<!is_tuple_like<T>::value && !is_mutable_container<T>::value &&
326 !std::is_void<T>::value>::type> {
327 static constexpr int value{1};
332struct type_count_base<T, typename std::enable_if<is_tuple_like<T>::value && !is_mutable_container<T>::value>::type> {
333 static constexpr int value{
334 std::tuple_size<typename std::decay<T>::type>::value};
338template <
typename T>
struct type_count_base<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
339 static constexpr int value{type_count_base<typename T::value_type>::value};
344template <typename T, enable_if_t<!std::is_same<T, long double>::value, detail::enabler> = detail::dummy>
345std::string float_to_string(T value,
int precision = std::numeric_limits<T>::max_digits10) {
346 std::array<char, 64> buffer{{}};
347 std::snprintf(buffer.data(), buffer.size(),
"%.*g", precision,
static_cast<double>(value));
348 return buffer.data();
351template <typename T, enable_if_t<std::is_same<T, long double>::value, detail::enabler> = detail::dummy>
352std::string float_to_string(T value,
int precision = std::numeric_limits<T>::max_digits10) {
353 std::array<char, 64> buffer{{}};
354 std::snprintf(buffer.data(), buffer.size(),
"%.*Lg", precision, value);
355 return buffer.data();
359template <typename T, enable_if_t<std::is_convertible<T, std::string>::value, detail::enabler> = detail::dummy>
360auto to_string(T &&value) ->
decltype(std::forward<T>(value)) {
361 return std::forward<T>(value);
366 enable_if_t<std::is_constructible<std::string, T>::value && !std::is_convertible<T, std::string>::value,
367 detail::enabler> = detail::dummy>
368std::string to_string(T &&value) {
369 return std::string(value);
373 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
374 is_ostreamable<T>::value && std::is_floating_point<typename std::decay<T>::type>::value,
375 detail::enabler> = detail::dummy>
376std::string to_string(T &&value) {
377 return float_to_string(value);
382 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
383 is_ostreamable<T>::value && !std::is_floating_point<typename std::decay<T>::type>::value,
384 detail::enabler> = detail::dummy>
385std::string to_string(T &&value) {
386 std::stringstream stream;
395 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
396 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value == 1,
397 detail::enabler> = detail::dummy>
398inline std::string to_string(T &&value);
402 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
403 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value >= 2,
404 detail::enabler> = detail::dummy>
405inline std::string to_string(T &&value);
410 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
412 !is_tuple_like<T>::value,
413 detail::enabler> = detail::dummy>
414inline std::string to_string(T &&) {
420 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
422 detail::enabler> = detail::dummy>
423inline std::string to_string(T &&variable) {
424 auto cval = variable.begin();
425 auto end = variable.end();
429 std::vector<std::string> defaults;
430 for(; cval != end; ++cval) {
431 defaults.emplace_back(CLI::detail::to_string(*cval));
433 return {
"[" + detail::join(defaults) +
"]"};
439template <
typename T, std::
size_t I>
440inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_value_string(T && );
443template <
typename T, std::
size_t I>
444inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_value_string(T &&value);
448 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
449 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value == 1,
451inline std::string to_string(T &&value) {
452 return to_string(std::get<0>(value));
457 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
458 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value >= 2,
460inline std::string to_string(T &&value) {
461 auto tname = std::string(1,
'[') + tuple_value_string<T, 0>(value);
462 tname.push_back(
']');
467template <
typename T, std::
size_t I>
468inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_value_string(T && ) {
469 return std::string{};
473template <
typename T, std::
size_t I>
474inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_value_string(T &&value) {
475 auto str = std::string{to_string(std::get<I>(value))} +
',' + tuple_value_string<T, I + 1>(value);
476 if(str.back() ==
',')
482template <
typename T1,
485 enable_if_t<std::is_same<T1, T2>::value, detail::enabler> = detail::dummy>
486auto checked_to_string(T &&value) ->
decltype(to_string(std::forward<T>(value))) {
487 return to_string(std::forward<T>(value));
491template <
typename T1,
494 enable_if_t<!std::is_same<T1, T2>::value, detail::enabler> = detail::dummy>
495std::string checked_to_string(T &&) {
496 return std::string{};
499template <typename T, enable_if_t<std::is_integral<T>::value, detail::enabler> = detail::dummy>
500std::string value_string(
const T &value) {
501 return std::to_string(value);
505template <typename T, enable_if_t<std::is_floating_point<T>::value, detail::enabler> = detail::dummy>
506std::string value_string(
const T &value) {
507 return float_to_string(value);
511template <typename T, enable_if_t<std::is_enum<T>::value, detail::enabler> = detail::dummy>
512std::string value_string(
const T &value) {
513 return std::to_string(
static_cast<typename std::underlying_type<T>::type
>(value));
517 enable_if_t<!std::is_enum<T>::value && !std::is_arithmetic<T>::value, detail::enabler> = detail::dummy>
518auto value_string(
const T &value) ->
decltype(to_string(value)) {
519 return to_string(value);
523template <
typename T,
typename def,
typename Enable =
void>
struct wrapped_type {
528template <
typename T,
typename def>
struct wrapped_type<T, def, typename std::enable_if<is_wrapper<T>::value>::type> {
529 using type =
typename T::value_type;
541template <
typename T,
typename Enable =
void>
struct type_count {
542 static const int value{0};
548 typename std::enable_if<!is_wrapper<T>::value && !is_tuple_like<T>::value && !is_complex<T>::value &&
549 !std::is_void<T>::value>::type> {
550 static constexpr int value{1};
554template <
typename T>
struct type_count<T, typename std::enable_if<is_complex<T>::value>::type> {
555 static constexpr int value{2};
559template <
typename T>
struct type_count<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
566 typename std::enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value &&
567 !is_mutable_container<T>::value>::type> {
568 static constexpr int value{type_count<typename T::value_type>::value};
572template <
typename T, std::
size_t I>
573constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type tuple_type_size() {
578template <
typename T, std::
size_t I>
579 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type tuple_type_size() {
580 return subtype_count<typename std::tuple_element<I, T>::type>::value + tuple_type_size<T, I + 1>();
585struct type_count<T, typename std::enable_if<is_tuple_like<T>::value && !is_complex<T>::value>::type> {
586 static constexpr int value{tuple_type_size<T, 0>()};
591 static constexpr int value{is_mutable_container<T>::value ? expected_max_vector_size : type_count<T>::value};
595template <
typename T,
typename Enable =
void>
struct type_count_min {
596 static const int value{0};
601struct type_count_min<
603 typename std::enable_if<!is_mutable_container<T>::value && !is_tuple_like<T>::value && !is_wrapper<T>::value &&
604 !is_complex<T>::value && !std::is_void<T>::value>::type> {
605 static constexpr int value{type_count<T>::value};
609template <
typename T>
struct type_count_min<T, typename std::enable_if<is_complex<T>::value>::type> {
610 static constexpr int value{1};
615struct type_count_min<
617 typename std::enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value>::type> {
618 static constexpr int value{subtype_count_min<typename T::value_type>::value};
622template <
typename T, std::
size_t I>
623constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type tuple_type_size_min() {
628template <
typename T, std::
size_t I>
629 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type tuple_type_size_min() {
635struct type_count_min<T, typename std::enable_if<is_tuple_like<T>::value && !is_complex<T>::value>::type> {
636 static constexpr int value{tuple_type_size_min<T, 0>()};
641 static constexpr int value{is_mutable_container<T>::value
642 ? ((type_count<T>::value < expected_max_vector_size) ? type_count<T>::value : 0)
643 : type_count_min<T>::value};
647template <
typename T,
typename Enable =
void>
struct expected_count {
648 static const int value{0};
653struct expected_count<T,
654 typename std::enable_if<!is_mutable_container<T>::value && !is_wrapper<T>::value &&
655 !std::is_void<T>::value>::type> {
656 static constexpr int value{1};
659template <
typename T>
struct expected_count<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
660 static constexpr int value{expected_max_vector_size};
665struct expected_count<T, typename std::enable_if<!is_mutable_container<T>::value && is_wrapper<T>::value>::type> {
666 static constexpr int value{expected_count<typename T::value_type>::value};
670enum class object_category : std::uint8_t {
673 unsigned_integral = 4,
677 number_constructible = 12,
678 double_constructible = 14,
679 integer_constructible = 16,
681 string_assignable = 23,
682 string_constructible = 24,
683 wstring_assignable = 25,
684 wstring_constructible = 26,
690 container_value = 80,
697template <
typename T,
typename Enable =
void>
struct classify_object {
698 static constexpr object_category value{object_category::other};
703struct classify_object<
705 typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, char>::value && std::is_signed<T>::value &&
706 !is_bool<T>::value && !std::is_enum<T>::value>::type> {
707 static constexpr object_category value{object_category::integral_value};
712struct classify_object<T,
713 typename std::enable_if<std::is_integral<T>::value && std::is_unsigned<T>::value &&
714 !std::is_same<T, char>::value && !is_bool<T>::value>::type> {
715 static constexpr object_category value{object_category::unsigned_integral};
720struct classify_object<T, typename std::enable_if<std::is_same<T, char>::value && !std::is_enum<T>::value>::type> {
721 static constexpr object_category value{object_category::char_value};
725template <
typename T>
struct classify_object<T, typename std::enable_if<is_bool<T>::value>::type> {
726 static constexpr object_category value{object_category::boolean_value};
730template <
typename T>
struct classify_object<T, typename std::enable_if<std::is_floating_point<T>::value>::type> {
731 static constexpr object_category value{object_category::floating_point};
736#define WIDE_STRING_CHECK \
737 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value
738#define STRING_CHECK true
740#define WIDE_STRING_CHECK true
741#define STRING_CHECK !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value
746struct classify_object<
748 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value && WIDE_STRING_CHECK &&
749 std::is_assignable<T &, std::string>::value>::type> {
750 static constexpr object_category value{object_category::string_assignable};
755struct classify_object<
757 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
758 !std::is_assignable<T &, std::string>::value && (type_count<T>::value == 1) &&
759 WIDE_STRING_CHECK && std::is_constructible<T, std::string>::value>::type> {
760 static constexpr object_category value{object_category::string_constructible};
765struct classify_object<T,
766 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
767 STRING_CHECK && std::is_assignable<T &, std::wstring>::value>::type> {
768 static constexpr object_category value{object_category::wstring_assignable};
772struct classify_object<
774 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
775 !std::is_assignable<T &, std::wstring>::value && (type_count<T>::value == 1) &&
776 STRING_CHECK && std::is_constructible<T, std::wstring>::value>::type> {
777 static constexpr object_category value{object_category::wstring_constructible};
781template <
typename T>
struct classify_object<T, typename std::enable_if<std::is_enum<T>::value>::type> {
782 static constexpr object_category value{object_category::enumeration};
785template <
typename T>
struct classify_object<T, typename std::enable_if<is_complex<T>::value>::type> {
786 static constexpr object_category value{object_category::complex_number};
791template <
typename T>
struct uncommon_type {
792 using type =
typename std::conditional<
793 !std::is_floating_point<T>::value && !std::is_integral<T>::value &&
794 !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value &&
795 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value &&
796 !is_complex<T>::value && !is_mutable_container<T>::value && !std::is_enum<T>::value,
798 std::false_type>::type;
799 static constexpr bool value = type::value;
804struct classify_object<T,
805 typename std::enable_if<(!is_mutable_container<T>::value && is_wrapper<T>::value &&
806 !is_tuple_like<T>::value && uncommon_type<T>::value)>::type> {
807 static constexpr object_category value{object_category::wrapper_value};
812struct classify_object<T,
813 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
814 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
815 is_direct_constructible<T, int>::value>::type> {
816 static constexpr object_category value{object_category::number_constructible};
821struct classify_object<T,
822 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
823 !is_wrapper<T>::value && !is_direct_constructible<T, double>::value &&
824 is_direct_constructible<T, int>::value>::type> {
825 static constexpr object_category value{object_category::integer_constructible};
830struct classify_object<T,
831 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
832 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
833 !is_direct_constructible<T, int>::value>::type> {
834 static constexpr object_category value{object_category::double_constructible};
839struct classify_object<
841 typename std::enable_if<is_tuple_like<T>::value &&
842 ((type_count<T>::value >= 2 && !is_wrapper<T>::value) ||
843 (uncommon_type<T>::value && !is_direct_constructible<T, double>::value &&
844 !is_direct_constructible<T, int>::value) ||
845 (uncommon_type<T>::value && type_count<T>::value >= 2))>::type> {
846 static constexpr object_category value{object_category::tuple_value};
855template <
typename T>
struct classify_object<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
856 static constexpr object_category value{object_category::container_value};
866 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> = detail::dummy>
867constexpr const char *type_name() {
872 enable_if_t<classify_object<T>::value == object_category::integral_value ||
873 classify_object<T>::value == object_category::integer_constructible,
874 detail::enabler> = detail::dummy>
875constexpr const char *type_name() {
880 enable_if_t<classify_object<T>::value == object_category::unsigned_integral, detail::enabler> = detail::dummy>
881constexpr const char *type_name() {
886 enable_if_t<classify_object<T>::value == object_category::floating_point ||
887 classify_object<T>::value == object_category::number_constructible ||
888 classify_object<T>::value == object_category::double_constructible,
889 detail::enabler> = detail::dummy>
890constexpr const char *type_name() {
896 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
897constexpr const char *type_name() {
903 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
904constexpr const char *type_name() {
910 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
911constexpr const char *type_name() {
917 enable_if_t<classify_object<T>::value >= object_category::string_assignable &&
918 classify_object<T>::value <= object_category::other,
919 detail::enabler> = detail::dummy>
920constexpr const char *type_name() {
925 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value >= 2,
926 detail::enabler> = detail::dummy>
927std::string type_name();
931 enable_if_t<classify_object<T>::value == object_category::container_value ||
932 classify_object<T>::value == object_category::wrapper_value,
933 detail::enabler> = detail::dummy>
934std::string type_name();
938 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value == 1,
939 detail::enabler> = detail::dummy>
940inline std::string type_name() {
941 return type_name<typename std::decay<typename std::tuple_element<0, T>::type>::type>();
945template <
typename T, std::
size_t I>
946inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_name() {
947 return std::string{};
951template <
typename T, std::
size_t I>
952inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_name() {
953 auto str = std::string{type_name<typename std::decay<typename std::tuple_element<I, T>::type>::type>()} +
',' +
954 tuple_name<T, I + 1>();
955 if(str.back() ==
',')
962 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value >= 2,
964inline std::string type_name() {
965 auto tname = std::string(1,
'[') + tuple_name<T, 0>();
966 tname.push_back(
']');
972 enable_if_t<classify_object<T>::value == object_category::container_value ||
973 classify_object<T>::value == object_category::wrapper_value,
975inline std::string type_name() {
976 return type_name<typename T::value_type>();
982template <typename T, enable_if_t<std::is_unsigned<T>::value, detail::enabler> = detail::dummy>
983bool integral_conversion(
const std::string &input, T &output)
noexcept {
988 const std::size_t sign_size = (input[0] ==
'+') ? 1U : 0U;
990 auto first_non_ws = input.find_first_not_of(
" \t\n\v\f\r");
991 if(first_non_ws != std::string::npos && input[first_non_ws] ==
'-') {
996 std::uint64_t output_ll = std::strtoull(input.c_str(), &val, 0);
997 if(errno == ERANGE) {
1000 output =
static_cast<T
>(output_ll);
1001 if(val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll) {
1005 std::int64_t output_sll = std::strtoll(input.c_str(), &val, 0);
1006 if(val == (input.c_str() + input.size())) {
1007 output = (output_sll < 0) ? static_cast<T>(0) : static_cast<T>(output_sll);
1008 return (
static_cast<std::int64_t
>(output) == output_sll);
1011 auto group_separators = get_group_separators();
1012 if(input.find_first_of(group_separators) != std::string::npos) {
1013 std::string nstring = input;
1014 for(
auto &separator : group_separators) {
1015 if(input.find_first_of(separator) != std::string::npos) {
1016 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1019 return integral_conversion(nstring, output);
1022 if(std::isspace(
static_cast<unsigned char>(input.front())) ||
1023 std::isspace(
static_cast<unsigned char>(input.back()))) {
1024 return integral_conversion(trim_copy(input), output);
1026 if(input.compare(sign_size, 2,
"0o") == 0 || input.compare(sign_size, 2,
"0O") == 0) {
1027 if(!std::isdigit(
static_cast<unsigned char>(input[sign_size + 2]))) {
1032 output_ll = std::strtoull(input.c_str() + sign_size + 2, &val, 8);
1033 if(errno == ERANGE) {
1036 output =
static_cast<T
>(output_ll);
1037 return (val != input.c_str() + sign_size + 2 && val == (input.c_str() + input.size()) &&
1038 static_cast<std::uint64_t
>(output) == output_ll);
1040 if(input.compare(sign_size, 2,
"0b") == 0 || input.compare(sign_size, 2,
"0B") == 0) {
1041 if(!std::isdigit(
static_cast<unsigned char>(input[sign_size + 2]))) {
1049 output_ll = std::strtoull(input.c_str() + sign_size + 2, &val, 2);
1050 if(errno == ERANGE) {
1053 output =
static_cast<T
>(output_ll);
1054 return (val != input.c_str() + sign_size + 2 && val == (input.c_str() + input.size()) &&
1055 static_cast<std::uint64_t
>(output) == output_ll);
1062template <typename T, enable_if_t<std::is_signed<T>::value, detail::enabler> = detail::dummy>
1063bool integral_conversion(
const std::string &input, T &output)
noexcept {
1067 char *val =
nullptr;
1069 std::int64_t output_ll = std::strtoll(input.c_str(), &val, 0);
1070 if(errno == ERANGE) {
1073 output =
static_cast<T
>(output_ll);
1074 if(val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll) {
1077 if(input ==
"true") {
1079 output =
static_cast<T
>(1);
1083 auto group_separators = get_group_separators();
1084 if(input.find_first_of(group_separators) != std::string::npos) {
1085 for(
auto &separator : group_separators) {
1086 if(input.find_first_of(separator) != std::string::npos) {
1087 std::string nstring = input;
1088 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1089 return integral_conversion(nstring, output);
1093 if(std::isspace(
static_cast<unsigned char>(input.front())) ||
1094 std::isspace(
static_cast<unsigned char>(input.back()))) {
1095 return integral_conversion(trim_copy(input), output);
1098 const std::size_t sign_size = (input[0] ==
'-' || input[0] ==
'+') ? 1U : 0U;
1099 if(input.compare(sign_size, 2,
"0o") == 0 || input.compare(sign_size, 2,
"0O") == 0) {
1100 if(!std::isdigit(
static_cast<unsigned char>(input[sign_size + 2]))) {
1103 const std::string digits = input.substr(0, sign_size) + input.substr(sign_size + 2);
1106 output_ll = std::strtoll(digits.c_str(), &val, 8);
1107 if(errno == ERANGE) {
1110 output =
static_cast<T
>(output_ll);
1111 return (val != digits.c_str() && val == (digits.c_str() + digits.size()) &&
1112 static_cast<std::int64_t
>(output) == output_ll);
1114 if(input.compare(sign_size, 2,
"0b") == 0 || input.compare(sign_size, 2,
"0B") == 0) {
1118 if(!std::isdigit(
static_cast<unsigned char>(input[sign_size + 2]))) {
1121 const std::string digits = input.substr(0, sign_size) + input.substr(sign_size + 2);
1124 output_ll = std::strtoll(digits.c_str(), &val, 2);
1125 if(errno == ERANGE) {
1128 output =
static_cast<T
>(output_ll);
1129 return (val != digits.c_str() && val == (digits.c_str() + digits.size()) &&
1130 static_cast<std::int64_t
>(output) == output_ll);
1137CLI11_INLINE std::int64_t to_flag_value(std::string val)
noexcept;
1140template <
typename T,
1141 enable_if_t<classify_object<T>::value == object_category::integral_value ||
1142 classify_object<T>::value == object_category::unsigned_integral,
1143 detail::enabler> = detail::dummy>
1144bool lexical_cast(
const std::string &input, T &output) {
1145 return integral_conversion(input, output);
1149template <
typename T,
1150 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> = detail::dummy>
1151bool lexical_cast(
const std::string &input, T &output) {
1152 if(input.size() == 1) {
1153 output =
static_cast<T
>(input[0]);
1159 bool result = integral_conversion(input, res);
1161 output =
static_cast<T
>(res);
1167template <
typename T,
1168 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
1169bool lexical_cast(
const std::string &input, T &output) {
1171 auto out = to_flag_value(input);
1174 }
else if(errno == ERANGE) {
1175 output = (input[0] !=
'-');
1183template <
typename T,
1184 enable_if_t<classify_object<T>::value == object_category::floating_point, detail::enabler> = detail::dummy>
1185bool lexical_cast(
const std::string &input, T &output) {
1189 char *val =
nullptr;
1190 auto output_ld = std::strtold(input.c_str(), &val);
1193 if(val == input.c_str()) {
1196 output =
static_cast<T
>(output_ld);
1197 if(val == (input.c_str() + input.size())) {
1200 while(std::isspace(
static_cast<unsigned char>(*val))) {
1202 if(val == (input.c_str() + input.size())) {
1208 auto group_separators = get_group_separators();
1209 if(input.find_first_of(group_separators) != std::string::npos) {
1210 for(
auto &separator : group_separators) {
1211 if(input.find_first_of(separator) != std::string::npos) {
1212 std::string nstring = input;
1213 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1214 return lexical_cast(nstring, output);
1222template <
typename T,
1223 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
1224bool lexical_cast(
const std::string &input, T &output) {
1228 using XC =
typename wrapped_type<T, double>::type;
1231 bool worked =
false;
1233 auto nloc = str1.find_last_of(
"+-");
1234 while(!worked && nloc != std::string::npos && nloc > 0) {
1235 auto str2 = str1.substr(nloc);
1236 if(str2.back() ==
'i' || str2.back() ==
'j')
1238 worked = lexical_cast(str1.substr(0, nloc), x) && lexical_cast(str2, y);
1239 nloc = str1.find_last_of(
"+-", nloc - 1);
1242 if(str1.back() ==
'i' || str1.back() ==
'j') {
1244 worked = lexical_cast(str1, y);
1247 worked = lexical_cast(str1, x);
1255 return from_stream(input, output);
1259template <
typename T,
1260 enable_if_t<classify_object<T>::value == object_category::string_assignable, detail::enabler> = detail::dummy>
1261bool lexical_cast(
const std::string &input, T &output) {
1269 enable_if_t<classify_object<T>::value == object_category::string_constructible, detail::enabler> = detail::dummy>
1270bool lexical_cast(
const std::string &input, T &output) {
1278 enable_if_t<classify_object<T>::value == object_category::wstring_assignable, detail::enabler> = detail::dummy>
1279bool lexical_cast(
const std::string &input, T &output) {
1280 output = widen(input);
1286 enable_if_t<classify_object<T>::value == object_category::wstring_constructible, detail::enabler> = detail::dummy>
1287bool lexical_cast(
const std::string &input, T &output) {
1288 output = T{widen(input)};
1293template <
typename T,
1294 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
1295bool lexical_cast(
const std::string &input, T &output) {
1296 typename std::underlying_type<T>::type val;
1297 if(!integral_conversion(input, val)) {
1300 output =
static_cast<T
>(val);
1305template <
typename T,
1306 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1307 std::is_assignable<T &, typename T::value_type>::value,
1308 detail::enabler> = detail::dummy>
1309bool lexical_cast(
const std::string &input, T &output) {
1310 typename T::value_type val;
1311 if(lexical_cast(input, val)) {
1315 return from_stream(input, output);
1318template <
typename T,
1319 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1320 !std::is_assignable<T &, typename T::value_type>::value && std::is_assignable<T &, T>::value,
1321 detail::enabler> = detail::dummy>
1322bool lexical_cast(
const std::string &input, T &output) {
1323 typename T::value_type val;
1324 if(lexical_cast(input, val)) {
1328 return from_stream(input, output);
1334 enable_if_t<classify_object<T>::value == object_category::number_constructible, detail::enabler> = detail::dummy>
1335bool lexical_cast(
const std::string &input, T &output) {
1337 if(integral_conversion(input, val)) {
1343 if(lexical_cast(input, dval)) {
1348 return from_stream(input, output);
1354 enable_if_t<classify_object<T>::value == object_category::integer_constructible, detail::enabler> = detail::dummy>
1355bool lexical_cast(
const std::string &input, T &output) {
1357 if(integral_conversion(input, val)) {
1361 return from_stream(input, output);
1367 enable_if_t<classify_object<T>::value == object_category::double_constructible, detail::enabler> = detail::dummy>
1368bool lexical_cast(
const std::string &input, T &output) {
1370 if(lexical_cast(input, val)) {
1374 return from_stream(input, output);
1378template <
typename T,
1379 enable_if_t<classify_object<T>::value == object_category::other && std::is_assignable<T &, int>::value,
1380 detail::enabler> = detail::dummy>
1381bool lexical_cast(
const std::string &input, T &output) {
1383 if(integral_conversion(input, val)) {
1385#pragma warning(push)
1386#pragma warning(disable : 4800)
1399 return from_stream(input, output);
1404template <
typename T,
1405 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1406 is_istreamable<T>::value,
1407 detail::enabler> = detail::dummy>
1408bool lexical_cast(
const std::string &input, T &output) {
1409 return from_stream(input, output);
1414template <
typename T,
1415 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1416 !is_istreamable<T>::value && !adl_detail::is_lexical_castable<T>::value,
1417 detail::enabler> = detail::dummy>
1418bool lexical_cast(
const std::string & , T & ) {
1419 static_assert(!std::is_same<T, T>::value,
1420 "option object type must have a lexical cast overload or streaming input operator(>>) defined, if it "
1421 "is convertible from another type use the add_option<T, XC>(...) with XC being the known type");
1427template <
typename AssignTo,
1429 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !is_wrapper<AssignTo>::value &&
1430 (classify_object<AssignTo>::value == object_category::string_assignable ||
1431 classify_object<AssignTo>::value == object_category::string_constructible ||
1432 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1433 classify_object<AssignTo>::value == object_category::wstring_constructible),
1434 detail::enabler> = detail::dummy>
1435bool lexical_assign(
const std::string &input, AssignTo &output) {
1436 return lexical_cast(input, output);
1441template <
typename AssignTo,
1443 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && is_wrapper<AssignTo>::value &&
1444 (classify_object<AssignTo>::value == object_category::string_assignable ||
1445 classify_object<AssignTo>::value == object_category::string_constructible ||
1446 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1447 classify_object<AssignTo>::value == object_category::wstring_constructible),
1448 detail::enabler> = detail::dummy>
1449bool lexical_assign(
const std::string &input, AssignTo &output) {
1451 output = AssignTo{};
1454 return lexical_cast(input, output);
1458template <
typename AssignTo,
1460 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, AssignTo>::value &&
1461 classify_object<AssignTo>::value != object_category::string_assignable &&
1462 classify_object<AssignTo>::value != object_category::string_constructible &&
1463 classify_object<AssignTo>::value != object_category::wstring_assignable &&
1464 classify_object<AssignTo>::value != object_category::wstring_constructible,
1465 detail::enabler> = detail::dummy>
1466bool lexical_assign(
const std::string &input, AssignTo &output) {
1468 output = AssignTo{};
1472 return lexical_cast(input, output);
1476template <
typename AssignTo,
1478 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1479 classify_object<AssignTo>::value == object_category::wrapper_value,
1480 detail::enabler> = detail::dummy>
1481bool lexical_assign(
const std::string &input, AssignTo &output) {
1483 typename AssignTo::value_type emptyVal{};
1487 return lexical_cast(input, output);
1492template <
typename AssignTo,
1494 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1495 classify_object<AssignTo>::value != object_category::wrapper_value &&
1496 std::is_assignable<AssignTo &, int>::value,
1497 detail::enabler> = detail::dummy>
1498bool lexical_assign(
const std::string &input, AssignTo &output) {
1504 if(lexical_cast(input, val)) {
1505#if defined(__clang__)
1507#pragma clang diagnostic push
1508#pragma clang diagnostic ignored "-Wsign-conversion"
1509#elif defined(__GNUC__) && (__GNUC__ == 8)
1511#pragma GCC diagnostic push
1512#pragma GCC diagnostic ignored "-Wsign-conversion"
1515#if defined(__clang__)
1516#pragma clang diagnostic pop
1517#elif defined(__GNUC__) && (__GNUC__ == 8)
1518#pragma GCC diagnostic pop
1526template <
typename AssignTo,
1528 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, ConvertTo &>::value,
1529 detail::enabler> = detail::dummy>
1530bool lexical_assign(
const std::string &input, AssignTo &output) {
1532 bool parse_result = (!input.empty()) ? lexical_cast(input, val) : true;
1536 return parse_result;
1543 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, ConvertTo &>::value &&
1544 std::is_move_assignable<AssignTo>::value,
1545 detail::enabler> = detail::dummy>
1546bool lexical_assign(
const std::string &input, AssignTo &output) {
1548 bool parse_result = input.empty() ? true : lexical_cast(input, val);
1550 output = AssignTo(val);
1552 return parse_result;
1556template <
typename AssignTo,
1558 enable_if_t<classify_object<ConvertTo>::value <= object_category::other &&
1559 classify_object<AssignTo>::value <= object_category::wrapper_value,
1560 detail::enabler> = detail::dummy>
1561bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1562 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1567template <
typename AssignTo,
1569 enable_if_t<(type_count<AssignTo>::value <= 2) && expected_count<AssignTo>::value == 1 &&
1570 is_tuple_like<ConvertTo>::value && type_count_base<ConvertTo>::value == 2,
1571 detail::enabler> = detail::dummy>
1572bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1574 using FirstType =
typename std::remove_const<typename std::tuple_element<0, ConvertTo>::type>::type;
1575 using SecondType =
typename std::tuple_element<1, ConvertTo>::type;
1578 bool retval = lexical_assign<FirstType, FirstType>(strings[0], v1);
1579 retval = retval && lexical_assign<SecondType, SecondType>((strings.size() > 1) ? strings[1] : std::string{}, v2);
1581 output = AssignTo{v1, v2};
1587template <
class AssignTo,
1589 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1590 type_count<ConvertTo>::value == 1,
1591 detail::enabler> = detail::dummy>
1592bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1593 output.erase(output.begin(), output.end());
1594 if(strings.empty()) {
1597 if(strings.size() == 1 && strings[0] ==
"{}") {
1600 bool skip_remaining =
false;
1601 if(strings.size() == 2 && strings[0] ==
"{}" && is_separator(strings[1])) {
1602 skip_remaining =
true;
1604 for(
const auto &elem : strings) {
1605 typename AssignTo::value_type out;
1606 bool retval = lexical_assign<typename AssignTo::value_type, typename ConvertTo::value_type>(elem, out);
1610 output.insert(output.end(), std::move(out));
1611 if(skip_remaining) {
1615 return (!output.empty());
1619template <class AssignTo, class ConvertTo, enable_if_t<is_complex<ConvertTo>::value, detail::enabler> = detail::dummy>
1620bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1622 if(strings.size() >= 2 && !strings[1].empty()) {
1623 using XC2 =
typename wrapped_type<ConvertTo, double>::type;
1625 auto str1 = strings[1];
1626 if(str1.back() ==
'i' || str1.back() ==
'j') {
1629 auto worked = lexical_cast(strings[0], x) && lexical_cast(str1, y);
1631 output = ConvertTo{x, y};
1635 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1639template <
class AssignTo,
1641 enable_if_t<is_mutable_container<AssignTo>::value && (expected_count<ConvertTo>::value == 1) &&
1642 (type_count<ConvertTo>::value == 1),
1643 detail::enabler> = detail::dummy>
1644bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1647 output.reserve(strings.size());
1648 for(
const auto &elem : strings) {
1650 output.emplace_back();
1651 retval = retval && lexical_assign<typename AssignTo::value_type, ConvertTo>(elem, output.back());
1653 return (!output.empty()) && retval;
1659template <
class AssignTo,
1661 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1662 type_count_base<ConvertTo>::value == 2,
1663 detail::enabler> = detail::dummy>
1664bool lexical_conversion(std::vector<std::string> strings, AssignTo &output);
1667template <
class AssignTo,
1669 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1670 type_count_base<ConvertTo>::value != 2 &&
1671 ((type_count<ConvertTo>::value > 2) ||
1672 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1673 detail::enabler> = detail::dummy>
1674bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1677template <
class AssignTo,
1679 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1680 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1681 type_count<ConvertTo>::value > 2),
1682 detail::enabler> = detail::dummy>
1683bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1687template <
typename AssignTo,
1689 enable_if_t<!is_tuple_like<AssignTo>::value && !is_mutable_container<AssignTo>::value &&
1690 classify_object<ConvertTo>::value != object_category::wrapper_value &&
1691 (is_mutable_container<ConvertTo>::value || type_count<ConvertTo>::value > 2),
1692 detail::enabler> = detail::dummy>
1693bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1695 if(strings.size() > 1 || (!strings.empty() && !(strings.front().empty()))) {
1697 auto retval = lexical_conversion<ConvertTo, ConvertTo>(strings, val);
1698 output = AssignTo{val};
1701 output = AssignTo{};
1706template <
class AssignTo,
class ConvertTo, std::
size_t I>
1707inline typename std::enable_if<(I >= type_count_base<AssignTo>::value),
bool>::type
1708tuple_conversion(
const std::vector<std::string> &, AssignTo &) {
1713template <
class AssignTo,
class ConvertTo>
1714inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && type_count<ConvertTo>::value == 1,
bool>::type
1715tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1716 auto retval = lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1717 strings.erase(strings.begin());
1722template <
class AssignTo,
class ConvertTo>
1723inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && (type_count<ConvertTo>::value > 1) &&
1724 type_count<ConvertTo>::value == type_count_min<ConvertTo>::value,
1726tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1727 auto retval = lexical_conversion<AssignTo, ConvertTo>(strings, output);
1728 strings.erase(strings.begin(), strings.begin() + type_count<ConvertTo>::value);
1733template <
class AssignTo,
class ConvertTo>
1734inline typename std::enable_if<is_mutable_container<ConvertTo>::value ||
1735 type_count<ConvertTo>::value != type_count_min<ConvertTo>::value,
1737tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1739 std::size_t index{subtype_count_min<ConvertTo>::value};
1740 const std::size_t mx_count{subtype_count<ConvertTo>::value};
1741 const std::size_t mx{(std::min)(mx_count, strings.size() - 1)};
1744 if(is_separator(strings[index])) {
1749 bool retval = lexical_conversion<AssignTo, ConvertTo>(
1750 std::vector<std::string>(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index)), output);
1751 if(strings.size() > index) {
1752 strings.erase(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index) + 1);
1760template <
class AssignTo,
class ConvertTo, std::
size_t I>
1761inline typename std::enable_if<(I < type_count_base<AssignTo>::value),
bool>::type
1762tuple_conversion(std::vector<std::string> strings, AssignTo &output) {
1764 using ConvertToElement =
typename std::
1765 conditional<is_tuple_like<ConvertTo>::value,
typename std::tuple_element<I, ConvertTo>::type, ConvertTo>::type;
1766 if(!strings.empty()) {
1767 retval = retval && tuple_type_conversion<typename std::tuple_element<I, AssignTo>::type, ConvertToElement>(
1768 strings, std::get<I>(output));
1770 retval = retval && tuple_conversion<AssignTo, ConvertTo, I + 1>(std::move(strings), output);
1775template <
class AssignTo,
1777 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1778 type_count_base<ConvertTo>::value == 2,
1780bool lexical_conversion(std::vector<std::string> strings, AssignTo &output) {
1782 while(!strings.empty()) {
1784 typename std::remove_const<typename std::tuple_element<0, typename ConvertTo::value_type>::type>::type v1{};
1785 typename std::tuple_element<1, typename ConvertTo::value_type>::type v2{};
1786 bool retval = tuple_type_conversion<decltype(v1), decltype(v1)>(strings, v1);
1787 if(!strings.empty()) {
1788 retval = retval && tuple_type_conversion<decltype(v2), decltype(v2)>(strings, v2);
1794 output.insert(output.end(),
typename AssignTo::value_type{v1, v2});
1799 return (!output.empty());
1803template <
class AssignTo,
1805 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1806 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1807 type_count<ConvertTo>::value > 2),
1809bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1811 !is_tuple_like<ConvertTo>::value || type_count_base<AssignTo>::value == type_count_base<ConvertTo>::value,
1812 "if the conversion type is defined as a tuple it must be the same size as the type you are converting to");
1813 return tuple_conversion<AssignTo, ConvertTo, 0>(strings, output);
1817template <
class AssignTo,
1819 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1820 type_count_base<ConvertTo>::value != 2 &&
1821 ((type_count<ConvertTo>::value > 2) ||
1822 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1824bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1827 std::vector<std::string> temp;
1829 std::size_t icount{0};
1830 std::size_t xcm{type_count<ConvertTo>::value};
1831 auto ii_max = strings.size();
1832 while(ii < ii_max) {
1833 temp.push_back(strings[ii]);
1836 if(icount == xcm || is_separator(temp.back()) || ii == ii_max) {
1837 if(
static_cast<int>(xcm) > type_count_min<ConvertTo>::value && is_separator(temp.back())) {
1840 typename AssignTo::value_type temp_out;
1842 lexical_conversion<typename AssignTo::value_type, typename ConvertTo::value_type>(temp, temp_out);
1847 output.insert(output.end(), std::move(temp_out));
1855template <
typename AssignTo,
1857 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1858 std::is_assignable<ConvertTo &, ConvertTo>::value,
1859 detail::enabler> = detail::dummy>
1860bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1861 if(strings.empty() || strings.front().empty()) {
1862 output = ConvertTo{};
1865 typename ConvertTo::value_type val;
1866 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1867 output = ConvertTo{val};
1874template <
typename AssignTo,
1876 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1877 !std::is_assignable<AssignTo &, ConvertTo>::value,
1878 detail::enabler> = detail::dummy>
1879bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1880 using ConvertType =
typename ConvertTo::value_type;
1881 if(strings.empty() || strings.front().empty()) {
1882 output = ConvertType{};
1886 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1894CLI11_INLINE std::string sum_string_vector(
const std::vector<std::string> &values);
1900#ifndef CLI11_COMPILE
1901#include "impl/TypeTools_inl.hpp"
Definition TypeTools.hpp:103
Check for complex.
Definition TypeTools.hpp:242
Definition TypeTools.hpp:184
Check for input streamability.
Definition TypeTools.hpp:231
Definition TypeTools.hpp:220
Definition TypeTools.hpp:306
This can be specialized to override the type deduction for IsMember.
Definition TypeTools.hpp:88
not a pointer
Definition TypeTools.hpp:122
Definition TypeTools.hpp:132
Definition TypeTools.hpp:267
Definition TypeTools.hpp:287
Definition TypeTools.hpp:298
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:164
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:168
Adaptor for set-like structure: This just wraps a normal container in a few utilities that do almost ...
Definition TypeTools.hpp:137
static auto second(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the second value (really just the underlying value).
Definition TypeTools.hpp:147
static auto first(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the first value (really just the underlying value).
Definition TypeTools.hpp:143
forward declare the subtype_count_min structure
Definition TypeTools.hpp:538
Set of overloads to get the type size of an object.
Definition TypeTools.hpp:535
This will only trigger for actual void type.
Definition TypeTools.hpp:318
This will only trigger for actual void type.
Definition TypeTools.hpp:541
template to get the underlying value type if it exists or use a default
Definition TypeTools.hpp:523
Check to see if something is bool (fail check by default).
Definition TypeTools.hpp:68
Check to see if something is copyable pointer.
Definition TypeTools.hpp:83
Check to see if something is a shared pointer.
Definition TypeTools.hpp:74
A copy of std::void_t from C++17 (helper for C++11 and C++14).
Definition TypeTools.hpp:57