24#include "Encoding.hpp"
25#include "StringTools.hpp"
36enum class enabler : std::uint8_t {};
39CLI11_MODULE_INLINE
constexpr enabler dummy = {};
47template <
bool B,
class T =
void>
using enable_if_t =
typename std::enable_if<B, T>::type;
55template <
typename... Ts>
using void_t =
typename make_void<Ts...>::type;
58template <
bool B,
class T,
class F>
using conditional_t =
typename std::conditional<B, T, F>::type;
61template <
typename T>
struct is_bool : std::false_type {};
64template <>
struct is_bool<bool> : std::true_type {};
70template <
typename T>
struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
73template <
typename T>
struct is_shared_ptr<const std::shared_ptr<T>> : std::true_type {};
87 using type = std::string;
97 template <
typename TT,
typename SS>
98 static auto test(
int) ->
decltype(lexical_cast(std::declval<const SS &>(), std::declval<TT &>()), std::true_type());
100 template <
typename,
typename>
static auto test(...) -> std::false_type;
103 static constexpr bool value =
decltype(test<T, S>(0))::value;
119template <
typename T>
struct element_type<T, typename std::enable_if<is_copyable_ptr<T>::value>::type> {
120 using type =
typename std::pointer_traits<T>::element_type;
130template <
typename T,
typename _ =
void>
struct pair_adaptor : std::false_type {
131 using value_type =
typename T::value_type;
132 using first_type =
typename std::remove_const<value_type>::type;
133 using second_type =
typename std::remove_const<value_type>::type;
136 template <
typename Q>
static auto first(Q &&pair_value) ->
decltype(std::forward<Q>(pair_value)) {
137 return std::forward<Q>(pair_value);
140 template <
typename Q>
static auto second(Q &&pair_value) ->
decltype(std::forward<Q>(pair_value)) {
141 return std::forward<Q>(pair_value);
150 conditional_t<false, void_t<typename T::value_type::first_type, typename T::value_type::second_type>, void>>
152 using value_type =
typename T::value_type;
153 using first_type =
typename std::remove_const<typename value_type::first_type>::type;
154 using second_type =
typename std::remove_const<typename value_type::second_type>::type;
157 template <
typename Q>
static auto first(Q &&pair_value) ->
decltype(std::get<0>(std::forward<Q>(pair_value))) {
158 return std::get<0>(std::forward<Q>(pair_value));
161 template <
typename Q>
static auto second(Q &&pair_value) ->
decltype(std::get<1>(std::forward<Q>(pair_value))) {
162 return std::get<1>(std::forward<Q>(pair_value));
173#pragma GCC diagnostic push
174#pragma GCC diagnostic ignored "-Wnarrowing"
178 template <
typename TT,
typename CC>
179 static auto test(
int, std::true_type) ->
decltype(
182#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
183#pragma nv_diag_suppress 2361
185#pragma diag_suppress 2361
188 TT{std::declval<CC>()}
190#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
191#pragma nv_diag_default 2361
193#pragma diag_default 2361
197 std::is_move_assignable<TT>());
199 template <
typename TT,
typename CC>
static auto test(
int, std::false_type) -> std::false_type;
201 template <
typename,
typename>
static auto test(...) -> std::false_type;
204 static constexpr bool value =
decltype(test<T, C>(0,
typename std::is_constructible<T, C>::type()))::value;
207#pragma GCC diagnostic pop
214 template <
typename TT,
typename SS>
215 static auto test(
int) ->
decltype(std::declval<SS &>() << std::declval<TT>(), std::true_type());
217 template <
typename,
typename>
static auto test(...) -> std::false_type;
220 static constexpr bool value =
decltype(test<T, S>(0))::value;
225 template <
typename TT,
typename SS>
226 static auto test(
int) ->
decltype(std::declval<SS &>() >> std::declval<TT &>(), std::true_type());
228 template <
typename,
typename>
static auto test(...) -> std::false_type;
231 static constexpr bool value =
decltype(test<T, S>(0))::value;
236 template <
typename TT>
237 static auto test(
int) ->
decltype(std::declval<TT>().real(), std::declval<TT>().imag(), std::true_type());
239 template <
typename>
static auto test(...) -> std::false_type;
242 static constexpr bool value =
decltype(test<T>(0))::value;
246template <typename T, enable_if_t<is_istreamable<T>::value, detail::enabler> = detail::dummy>
247bool from_stream(
const std::string &istring, T &obj) {
248 std::istringstream is;
251 return !is.fail() && !is.rdbuf()->in_avail();
254template <typename T, enable_if_t<!is_istreamable<T>::value, detail::enabler> = detail::dummy>
255bool from_stream(
const std::string & , T & ) {
269 void_t<typename T::value_type,
270 decltype(std::declval<T>().end()),
271 decltype(std::declval<T>().clear()),
272 decltype(std::declval<T>().insert(std::declval<decltype(std::declval<T>().end())>(),
273 std::declval<const typename T::value_type &>()))>,
274 void>> :
public conditional_t<std::is_constructible<T, std::string>::value ||
275 std::is_constructible<T, std::wstring>::value,
287 conditional_t<false, void_t<decltype(std::declval<T>().end()), decltype(std::declval<T>().begin())>, void>>
288 :
public std::true_type {};
291template <
typename T,
typename _ =
void>
struct is_wrapper : std::false_type {};
295struct is_wrapper<T, conditional_t<false, void_t<typename T::value_type>, void>> :
public std::true_type {};
300 template <typename SS, enable_if_t<!is_complex<SS>::value, detail::enabler> = detail::dummy>
303 static auto test(
int) ->
decltype(std::tuple_size<typename std::decay<SS>::type>::value, std::true_type{});
304 template <
typename>
static auto test(...) -> std::false_type;
307 static constexpr bool value =
decltype(test<S>(0))::value;
312 static const int value{0};
318 typename std::enable_if<!is_tuple_like<T>::value && !is_mutable_container<T>::value &&
319 !std::is_void<T>::value>::type> {
320 static constexpr int value{1};
325struct type_count_base<T, typename std::enable_if<is_tuple_like<T>::value && !is_mutable_container<T>::value>::type> {
326 static constexpr int value{
327 std::tuple_size<typename std::decay<T>::type>::value};
331template <
typename T>
struct type_count_base<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
336template <typename T, enable_if_t<std::is_convertible<T, std::string>::value, detail::enabler> = detail::dummy>
337auto to_string(T &&value) ->
decltype(std::forward<T>(value)) {
338 return std::forward<T>(value);
343 enable_if_t<std::is_constructible<std::string, T>::value && !std::is_convertible<T, std::string>::value,
344 detail::enabler> = detail::dummy>
345std::string to_string(T &&value) {
346 return std::string(value);
351 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
352 is_ostreamable<T>::value,
353 detail::enabler> = detail::dummy>
354std::string to_string(T &&value) {
355 std::stringstream stream;
364 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
365 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value == 1,
366 detail::enabler> = detail::dummy>
367inline std::string to_string(T &&value);
371 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
372 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value >= 2,
373 detail::enabler> = detail::dummy>
374inline std::string to_string(T &&value);
379 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
380 !is_ostreamable<T>::value && !is_readable_container<typename std::remove_const<T>::type>::value &&
381 !is_tuple_like<T>::value,
382 detail::enabler> = detail::dummy>
383inline std::string to_string(T &&) {
389 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
390 !is_ostreamable<T>::value && is_readable_container<T>::value && !is_tuple_like<T>::value,
391 detail::enabler> = detail::dummy>
392inline std::string to_string(T &&variable) {
393 auto cval = variable.begin();
394 auto end = variable.end();
398 std::vector<std::string> defaults;
400 defaults.emplace_back(CLI::detail::to_string(*cval));
403 return {
"[" + detail::join(defaults) +
"]"};
409template <
typename T, std::
size_t I>
410inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_value_string(T && );
413template <
typename T, std::
size_t I>
414inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_value_string(T &&value);
418 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
419 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value == 1,
421inline std::string to_string(T &&value) {
422 return to_string(std::get<0>(value));
427 enable_if_t<!std::is_convertible<T, std::string>::value && !std::is_constructible<std::string, T>::value &&
428 !is_ostreamable<T>::value && is_tuple_like<T>::value && type_count_base<T>::value >= 2,
430inline std::string to_string(T &&value) {
431 auto tname = std::string(1,
'[') + tuple_value_string<T, 0>(value);
432 tname.push_back(
']');
437template <
typename T, std::
size_t I>
438inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_value_string(T && ) {
439 return std::string{};
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) {
445 auto str = std::string{to_string(std::get<I>(value))} +
',' + tuple_value_string<T, I + 1>(value);
446 if(str.back() ==
',')
452template <
typename T1,
455 enable_if_t<std::is_same<T1, T2>::value, detail::enabler> = detail::dummy>
456auto checked_to_string(T &&value) ->
decltype(to_string(std::forward<T>(value))) {
457 return to_string(std::forward<T>(value));
461template <
typename T1,
464 enable_if_t<!std::is_same<T1, T2>::value, detail::enabler> = detail::dummy>
465std::string checked_to_string(T &&) {
466 return std::string{};
469template <typename T, enable_if_t<std::is_arithmetic<T>::value, detail::enabler> = detail::dummy>
470std::string value_string(
const T &value) {
471 return std::to_string(value);
474template <typename T, enable_if_t<std::is_enum<T>::value, detail::enabler> = detail::dummy>
475std::string value_string(
const T &value) {
476 return std::to_string(
static_cast<typename std::underlying_type<T>::type
>(value));
480 enable_if_t<!std::is_enum<T>::value && !std::is_arithmetic<T>::value, detail::enabler> = detail::dummy>
481auto value_string(
const T &value) ->
decltype(to_string(value)) {
482 return to_string(value);
486template <
typename T,
typename def,
typename Enable =
void>
struct wrapped_type {
491template <
typename T,
typename def>
struct wrapped_type<T, def, typename std::enable_if<is_wrapper<T>::value>::type> {
492 using type =
typename T::value_type;
504template <
typename T,
typename Enable =
void>
struct type_count {
505 static const int value{0};
511 typename std::enable_if<!is_wrapper<T>::value && !is_tuple_like<T>::value && !is_complex<T>::value &&
512 !std::is_void<T>::value>::type> {
513 static constexpr int value{1};
517template <
typename T>
struct type_count<T, typename std::enable_if<is_complex<T>::value>::type> {
518 static constexpr int value{2};
522template <
typename T>
struct type_count<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
529 typename std::enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value &&
530 !is_mutable_container<T>::value>::type> {
535template <
typename T, std::
size_t I>
536constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type tuple_type_size() {
541template <
typename T, std::
size_t I>
542 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type tuple_type_size() {
543 return subtype_count<typename std::tuple_element<I, T>::type>::value + tuple_type_size<T, I + 1>();
548struct type_count<T, typename std::enable_if<is_tuple_like<T>::value && !is_complex<T>::value>::type> {
549 static constexpr int value{tuple_type_size<T, 0>()};
553template <
typename T>
struct subtype_count {
554 static constexpr int value{is_mutable_container<T>::value ? expected_max_vector_size : type_count<T>::value};
558template <
typename T,
typename Enable =
void>
struct type_count_min {
559 static const int value{0};
564struct type_count_min<
566 typename std::enable_if<!is_mutable_container<T>::value && !is_tuple_like<T>::value && !is_wrapper<T>::value &&
567 !is_complex<T>::value && !std::is_void<T>::value>::type> {
568 static constexpr int value{type_count<T>::value};
572template <
typename T>
struct type_count_min<T, typename std::enable_if<is_complex<T>::value>::type> {
573 static constexpr int value{1};
578struct type_count_min<
580 typename std::enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value>::type> {
581 static constexpr int value{subtype_count_min<typename T::value_type>::value};
585template <
typename T, std::
size_t I>
586constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type tuple_type_size_min() {
591template <
typename T, std::
size_t I>
592 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type tuple_type_size_min() {
593 return subtype_count_min<typename std::tuple_element<I, T>::type>::value + tuple_type_size_min<T, I + 1>();
598struct type_count_min<T, typename std::enable_if<is_tuple_like<T>::value && !is_complex<T>::value>::type> {
599 static constexpr int value{tuple_type_size_min<T, 0>()};
603template <
typename T>
struct subtype_count_min {
604 static constexpr int value{is_mutable_container<T>::value
605 ? ((type_count<T>::value < expected_max_vector_size) ? type_count<T>::value : 0)
606 : type_count_min<T>::value};
610template <
typename T,
typename Enable =
void>
struct expected_count {
611 static const int value{0};
616struct expected_count<T,
617 typename std::enable_if<!is_mutable_container<T>::value && !is_wrapper<T>::value &&
618 !std::is_void<T>::value>::type> {
619 static constexpr int value{1};
622template <
typename T>
struct expected_count<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
623 static constexpr int value{expected_max_vector_size};
628struct expected_count<T, typename std::enable_if<!is_mutable_container<T>::value && is_wrapper<T>::value>::type> {
629 static constexpr int value{expected_count<typename T::value_type>::value};
633enum class object_category : std::uint8_t {
636 unsigned_integral = 4,
640 number_constructible = 12,
641 double_constructible = 14,
642 integer_constructible = 16,
644 string_assignable = 23,
645 string_constructible = 24,
646 wstring_assignable = 25,
647 wstring_constructible = 26,
653 container_value = 80,
660template <
typename T,
typename Enable =
void>
struct classify_object {
661 static constexpr object_category value{object_category::other};
666struct classify_object<
668 typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, char>::value && std::is_signed<T>::value &&
669 !is_bool<T>::value && !std::is_enum<T>::value>::type> {
670 static constexpr object_category value{object_category::integral_value};
675struct classify_object<T,
676 typename std::enable_if<std::is_integral<T>::value && std::is_unsigned<T>::value &&
677 !std::is_same<T, char>::value && !is_bool<T>::value>::type> {
678 static constexpr object_category value{object_category::unsigned_integral};
683struct classify_object<T, typename std::enable_if<std::is_same<T, char>::value && !std::is_enum<T>::value>::type> {
684 static constexpr object_category value{object_category::char_value};
688template <
typename T>
struct classify_object<T, typename std::enable_if<is_bool<T>::value>::type> {
689 static constexpr object_category value{object_category::boolean_value};
693template <
typename T>
struct classify_object<T, typename std::enable_if<std::is_floating_point<T>::value>::type> {
694 static constexpr object_category value{object_category::floating_point};
699#define WIDE_STRING_CHECK \
700 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value
701#define STRING_CHECK true
703#define WIDE_STRING_CHECK true
704#define STRING_CHECK !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value
709struct classify_object<
711 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value && WIDE_STRING_CHECK &&
712 std::is_assignable<T &, std::string>::value>::type> {
713 static constexpr object_category value{object_category::string_assignable};
718struct classify_object<
720 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
721 !std::is_assignable<T &, std::string>::value && (type_count<T>::value == 1) &&
722 WIDE_STRING_CHECK && std::is_constructible<T, std::string>::value>::type> {
723 static constexpr object_category value{object_category::string_constructible};
728struct classify_object<T,
729 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
730 STRING_CHECK && std::is_assignable<T &, std::wstring>::value>::type> {
731 static constexpr object_category value{object_category::wstring_assignable};
735struct classify_object<
737 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
738 !std::is_assignable<T &, std::wstring>::value && (type_count<T>::value == 1) &&
739 STRING_CHECK && std::is_constructible<T, std::wstring>::value>::type> {
740 static constexpr object_category value{object_category::wstring_constructible};
744template <
typename T>
struct classify_object<T, typename std::enable_if<std::is_enum<T>::value>::type> {
745 static constexpr object_category value{object_category::enumeration};
748template <
typename T>
struct classify_object<T, typename std::enable_if<is_complex<T>::value>::type> {
749 static constexpr object_category value{object_category::complex_number};
754template <
typename T>
struct uncommon_type {
755 using type =
typename std::conditional<
756 !std::is_floating_point<T>::value && !std::is_integral<T>::value &&
757 !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value &&
758 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value &&
759 !is_complex<T>::value && !is_mutable_container<T>::value && !std::is_enum<T>::value,
761 std::false_type>::type;
762 static constexpr bool value = type::value;
767struct classify_object<T,
768 typename std::enable_if<(!is_mutable_container<T>::value && is_wrapper<T>::value &&
769 !is_tuple_like<T>::value && uncommon_type<T>::value)>::type> {
770 static constexpr object_category value{object_category::wrapper_value};
775struct classify_object<T,
776 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
777 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
778 is_direct_constructible<T, int>::value>::type> {
779 static constexpr object_category value{object_category::number_constructible};
784struct classify_object<T,
785 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
786 !is_wrapper<T>::value && !is_direct_constructible<T, double>::value &&
787 is_direct_constructible<T, int>::value>::type> {
788 static constexpr object_category value{object_category::integer_constructible};
793struct classify_object<T,
794 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
795 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
796 !is_direct_constructible<T, int>::value>::type> {
797 static constexpr object_category value{object_category::double_constructible};
802struct classify_object<
804 typename std::enable_if<is_tuple_like<T>::value &&
805 ((type_count<T>::value >= 2 && !is_wrapper<T>::value) ||
806 (uncommon_type<T>::value && !is_direct_constructible<T, double>::value &&
807 !is_direct_constructible<T, int>::value) ||
808 (uncommon_type<T>::value && type_count<T>::value >= 2))>::type> {
809 static constexpr object_category value{object_category::tuple_value};
818template <
typename T>
struct classify_object<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
819 static constexpr object_category value{object_category::container_value};
829 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> = detail::dummy>
830constexpr const char *type_name() {
835 enable_if_t<classify_object<T>::value == object_category::integral_value ||
836 classify_object<T>::value == object_category::integer_constructible,
837 detail::enabler> = detail::dummy>
838constexpr const char *type_name() {
843 enable_if_t<classify_object<T>::value == object_category::unsigned_integral, detail::enabler> = detail::dummy>
844constexpr const char *type_name() {
849 enable_if_t<classify_object<T>::value == object_category::floating_point ||
850 classify_object<T>::value == object_category::number_constructible ||
851 classify_object<T>::value == object_category::double_constructible,
852 detail::enabler> = detail::dummy>
853constexpr const char *type_name() {
859 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
860constexpr const char *type_name() {
866 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
867constexpr const char *type_name() {
873 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
874constexpr const char *type_name() {
880 enable_if_t<classify_object<T>::value >= object_category::string_assignable &&
881 classify_object<T>::value <= object_category::other,
882 detail::enabler> = detail::dummy>
883constexpr const char *type_name() {
888 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value >= 2,
889 detail::enabler> = detail::dummy>
890std::string type_name();
894 enable_if_t<classify_object<T>::value == object_category::container_value ||
895 classify_object<T>::value == object_category::wrapper_value,
896 detail::enabler> = detail::dummy>
897std::string type_name();
901 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value == 1,
902 detail::enabler> = detail::dummy>
903inline std::string type_name() {
904 return type_name<typename std::decay<typename std::tuple_element<0, T>::type>::type>();
908template <
typename T, std::
size_t I>
909inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_name() {
910 return std::string{};
914template <
typename T, std::
size_t I>
915inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_name() {
916 auto str = std::string{type_name<typename std::decay<typename std::tuple_element<I, T>::type>::type>()} +
',' +
917 tuple_name<T, I + 1>();
918 if(str.back() ==
',')
925 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value >= 2,
927inline std::string type_name() {
928 auto tname = std::string(1,
'[') + tuple_name<T, 0>();
929 tname.push_back(
']');
935 enable_if_t<classify_object<T>::value == object_category::container_value ||
936 classify_object<T>::value == object_category::wrapper_value,
938inline std::string type_name() {
939 return type_name<typename T::value_type>();
945template <typename T, enable_if_t<std::is_unsigned<T>::value, detail::enabler> = detail::dummy>
946bool integral_conversion(
const std::string &input, T &output)
noexcept {
952 auto first_non_ws = input.find_first_not_of(
" \t\n\v\f\r");
953 if(first_non_ws != std::string::npos && input[first_non_ws] ==
'-') {
958 std::uint64_t output_ll = std::strtoull(input.c_str(), &val, 0);
959 if(errno == ERANGE) {
962 output =
static_cast<T
>(output_ll);
963 if(val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll) {
967 std::int64_t output_sll = std::strtoll(input.c_str(), &val, 0);
968 if(val == (input.c_str() + input.size())) {
969 output = (output_sll < 0) ? static_cast<T>(0) : static_cast<T>(output_sll);
970 return (
static_cast<std::int64_t
>(output) == output_sll);
973 auto group_separators = get_group_separators();
974 if(input.find_first_of(group_separators) != std::string::npos) {
975 std::string nstring = input;
976 for(
auto &separator : group_separators) {
977 if(input.find_first_of(separator) != std::string::npos) {
978 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
981 return integral_conversion(nstring, output);
984 if(std::isspace(
static_cast<unsigned char>(input.back()))) {
985 return integral_conversion(trim_copy(input), output);
987 if(input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0) {
990 output_ll = std::strtoull(input.c_str() + 2, &val, 8);
991 if(errno == ERANGE) {
994 output =
static_cast<T
>(output_ll);
995 return (val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll);
997 if(input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0) {
1003 output_ll = std::strtoull(input.c_str() + 2, &val, 2);
1004 if(errno == ERANGE) {
1007 output =
static_cast<T
>(output_ll);
1008 return (val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll);
1015template <typename T, enable_if_t<std::is_signed<T>::value, detail::enabler> = detail::dummy>
1016bool integral_conversion(
const std::string &input, T &output)
noexcept {
1020 char *val =
nullptr;
1022 std::int64_t output_ll = std::strtoll(input.c_str(), &val, 0);
1023 if(errno == ERANGE) {
1026 output =
static_cast<T
>(output_ll);
1027 if(val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll) {
1030 if(input ==
"true") {
1032 output =
static_cast<T
>(1);
1036 auto group_separators = get_group_separators();
1037 if(input.find_first_of(group_separators) != std::string::npos) {
1038 for(
auto &separator : group_separators) {
1039 if(input.find_first_of(separator) != std::string::npos) {
1040 std::string nstring = input;
1041 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1042 return integral_conversion(nstring, output);
1046 if(std::isspace(
static_cast<unsigned char>(input.back()))) {
1047 return integral_conversion(trim_copy(input), output);
1049 if(input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0) {
1052 output_ll = std::strtoll(input.c_str() + 2, &val, 8);
1053 if(errno == ERANGE) {
1056 output =
static_cast<T
>(output_ll);
1057 return (val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll);
1059 if(input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0) {
1065 output_ll = std::strtoll(input.c_str() + 2, &val, 2);
1066 if(errno == ERANGE) {
1069 output =
static_cast<T
>(output_ll);
1070 return (val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll);
1077inline std::int64_t to_flag_value(std::string val)
noexcept {
1078 static const std::string trueString(
"true");
1079 static const std::string falseString(
"false");
1080 if(val == trueString) {
1083 if(val == falseString) {
1086 val = detail::to_lower(std::move(val));
1087 std::int64_t ret = 0;
1088 if(val.size() == 1) {
1089 if(val[0] >=
'1' && val[0] <=
'9') {
1090 return (
static_cast<std::int64_t
>(val[0]) -
'0');
1110 if(val == trueString || val ==
"on" || val ==
"yes" || val ==
"enable") {
1112 }
else if(val == falseString || val ==
"off" || val ==
"no" || val ==
"disable") {
1115 char *loc_ptr{
nullptr};
1116 ret = std::strtoll(val.c_str(), &loc_ptr, 0);
1117 if(loc_ptr != (val.c_str() + val.size()) && errno == 0) {
1125template <
typename T,
1126 enable_if_t<classify_object<T>::value == object_category::integral_value ||
1127 classify_object<T>::value == object_category::unsigned_integral,
1128 detail::enabler> = detail::dummy>
1129bool lexical_cast(
const std::string &input, T &output) {
1130 return integral_conversion(input, output);
1134template <
typename T,
1135 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> = detail::dummy>
1136bool lexical_cast(
const std::string &input, T &output) {
1137 if(input.size() == 1) {
1138 output =
static_cast<T
>(input[0]);
1144 bool result = integral_conversion(input, res);
1146 output =
static_cast<T
>(res);
1152template <
typename T,
1153 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
1154bool lexical_cast(
const std::string &input, T &output) {
1156 auto out = to_flag_value(input);
1159 }
else if(errno == ERANGE) {
1160 output = (input[0] !=
'-');
1168template <
typename T,
1169 enable_if_t<classify_object<T>::value == object_category::floating_point, detail::enabler> = detail::dummy>
1170bool lexical_cast(
const std::string &input, T &output) {
1174 char *val =
nullptr;
1175 auto output_ld = std::strtold(input.c_str(), &val);
1178 if(val == input.c_str()) {
1181 output =
static_cast<T
>(output_ld);
1182 if(val == (input.c_str() + input.size())) {
1185 while(std::isspace(
static_cast<unsigned char>(*val))) {
1187 if(val == (input.c_str() + input.size())) {
1193 auto group_separators = get_group_separators();
1194 if(input.find_first_of(group_separators) != std::string::npos) {
1195 for(
auto &separator : group_separators) {
1196 if(input.find_first_of(separator) != std::string::npos) {
1197 std::string nstring = input;
1198 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1199 return lexical_cast(nstring, output);
1207template <
typename T,
1208 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
1209bool lexical_cast(
const std::string &input, T &output) {
1210 using XC =
typename wrapped_type<T, double>::type;
1213 bool worked =
false;
1214 auto nloc = str1.find_last_of(
"+-");
1215 if(nloc != std::string::npos && nloc > 0) {
1216 worked = lexical_cast(str1.substr(0, nloc), x);
1217 str1 = str1.substr(nloc);
1218 if(str1.back() ==
'i' || str1.back() ==
'j')
1220 worked = worked && lexical_cast(str1, y);
1222 if(str1.back() ==
'i' || str1.back() ==
'j') {
1224 worked = lexical_cast(str1, y);
1227 worked = lexical_cast(str1, x);
1235 return from_stream(input, output);
1239template <
typename T,
1240 enable_if_t<classify_object<T>::value == object_category::string_assignable, detail::enabler> = detail::dummy>
1241bool lexical_cast(
const std::string &input, T &output) {
1249 enable_if_t<classify_object<T>::value == object_category::string_constructible, detail::enabler> = detail::dummy>
1250bool lexical_cast(
const std::string &input, T &output) {
1258 enable_if_t<classify_object<T>::value == object_category::wstring_assignable, detail::enabler> = detail::dummy>
1259bool lexical_cast(
const std::string &input, T &output) {
1260 output = widen(input);
1266 enable_if_t<classify_object<T>::value == object_category::wstring_constructible, detail::enabler> = detail::dummy>
1267bool lexical_cast(
const std::string &input, T &output) {
1268 output = T{widen(input)};
1273template <
typename T,
1274 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
1275bool lexical_cast(
const std::string &input, T &output) {
1276 typename std::underlying_type<T>::type val;
1277 if(!integral_conversion(input, val)) {
1280 output =
static_cast<T
>(val);
1285template <
typename T,
1286 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1287 std::is_assignable<T &, typename T::value_type>::value,
1288 detail::enabler> = detail::dummy>
1289bool lexical_cast(
const std::string &input, T &output) {
1290 typename T::value_type val;
1291 if(lexical_cast(input, val)) {
1295 return from_stream(input, output);
1298template <
typename T,
1299 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1300 !std::is_assignable<T &, typename T::value_type>::value && std::is_assignable<T &, T>::value,
1301 detail::enabler> = detail::dummy>
1302bool lexical_cast(
const std::string &input, T &output) {
1303 typename T::value_type val;
1304 if(lexical_cast(input, val)) {
1308 return from_stream(input, output);
1314 enable_if_t<classify_object<T>::value == object_category::number_constructible, detail::enabler> = detail::dummy>
1315bool lexical_cast(
const std::string &input, T &output) {
1317 if(integral_conversion(input, val)) {
1323 if(lexical_cast(input, dval)) {
1328 return from_stream(input, output);
1334 enable_if_t<classify_object<T>::value == object_category::integer_constructible, detail::enabler> = detail::dummy>
1335bool lexical_cast(
const std::string &input, T &output) {
1337 if(integral_conversion(input, val)) {
1341 return from_stream(input, output);
1347 enable_if_t<classify_object<T>::value == object_category::double_constructible, detail::enabler> = detail::dummy>
1348bool lexical_cast(
const std::string &input, T &output) {
1350 if(lexical_cast(input, val)) {
1354 return from_stream(input, output);
1358template <
typename T,
1359 enable_if_t<classify_object<T>::value == object_category::other && std::is_assignable<T &, int>::value,
1360 detail::enabler> = detail::dummy>
1361bool lexical_cast(
const std::string &input, T &output) {
1363 if(integral_conversion(input, val)) {
1365#pragma warning(push)
1366#pragma warning(disable : 4800)
1379 return from_stream(input, output);
1384template <
typename T,
1385 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1386 is_istreamable<T>::value,
1387 detail::enabler> = detail::dummy>
1388bool lexical_cast(
const std::string &input, T &output) {
1389 return from_stream(input, output);
1394template <
typename T,
1395 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1396 !is_istreamable<T>::value && !adl_detail::is_lexical_castable<T>::value,
1397 detail::enabler> = detail::dummy>
1398bool lexical_cast(
const std::string & , T & ) {
1399 static_assert(!std::is_same<T, T>::value,
1400 "option object type must have a lexical cast overload or streaming input operator(>>) defined, if it "
1401 "is convertible from another type use the add_option<T, XC>(...) with XC being the known type");
1407template <
typename AssignTo,
1409 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !is_wrapper<AssignTo>::value &&
1410 (classify_object<AssignTo>::value == object_category::string_assignable ||
1411 classify_object<AssignTo>::value == object_category::string_constructible ||
1412 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1413 classify_object<AssignTo>::value == object_category::wstring_constructible),
1414 detail::enabler> = detail::dummy>
1415bool lexical_assign(
const std::string &input, AssignTo &output) {
1416 return lexical_cast(input, output);
1421template <
typename AssignTo,
1423 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && is_wrapper<AssignTo>::value &&
1424 (classify_object<AssignTo>::value == object_category::string_assignable ||
1425 classify_object<AssignTo>::value == object_category::string_constructible ||
1426 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1427 classify_object<AssignTo>::value == object_category::wstring_constructible),
1428 detail::enabler> = detail::dummy>
1429bool lexical_assign(
const std::string &input, AssignTo &output) {
1431 output = AssignTo{};
1434 return lexical_cast(input, output);
1438template <
typename AssignTo,
1440 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, AssignTo>::value &&
1441 classify_object<AssignTo>::value != object_category::string_assignable &&
1442 classify_object<AssignTo>::value != object_category::string_constructible &&
1443 classify_object<AssignTo>::value != object_category::wstring_assignable &&
1444 classify_object<AssignTo>::value != object_category::wstring_constructible,
1445 detail::enabler> = detail::dummy>
1446bool lexical_assign(
const std::string &input, AssignTo &output) {
1448 output = AssignTo{};
1452 return lexical_cast(input, output);
1456template <
typename AssignTo,
1458 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1459 classify_object<AssignTo>::value == object_category::wrapper_value,
1460 detail::enabler> = detail::dummy>
1461bool lexical_assign(
const std::string &input, AssignTo &output) {
1463 typename AssignTo::value_type emptyVal{};
1467 return lexical_cast(input, output);
1472template <
typename AssignTo,
1474 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1475 classify_object<AssignTo>::value != object_category::wrapper_value &&
1476 std::is_assignable<AssignTo &, int>::value,
1477 detail::enabler> = detail::dummy>
1478bool lexical_assign(
const std::string &input, AssignTo &output) {
1484 if(lexical_cast(input, val)) {
1485#if defined(__clang__)
1487#pragma clang diagnostic push
1488#pragma clang diagnostic ignored "-Wsign-conversion"
1489#elif defined(__GNUC__) && (__GNUC__ == 8)
1491#pragma GCC diagnostic push
1492#pragma GCC diagnostic ignored "-Wsign-conversion"
1495#if defined(__clang__)
1496#pragma clang diagnostic pop
1497#elif defined(__GNUC__) && (__GNUC__ == 8)
1498#pragma GCC diagnostic pop
1506template <
typename AssignTo,
1508 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, ConvertTo &>::value,
1509 detail::enabler> = detail::dummy>
1510bool lexical_assign(
const std::string &input, AssignTo &output) {
1512 bool parse_result = (!input.empty()) ? lexical_cast(input, val) : true;
1516 return parse_result;
1523 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, ConvertTo &>::value &&
1524 std::is_move_assignable<AssignTo>::value,
1525 detail::enabler> = detail::dummy>
1526bool lexical_assign(
const std::string &input, AssignTo &output) {
1528 bool parse_result = input.empty() ? true : lexical_cast(input, val);
1530 output = AssignTo(val);
1532 return parse_result;
1536template <
typename AssignTo,
1538 enable_if_t<classify_object<ConvertTo>::value <= object_category::other &&
1539 classify_object<AssignTo>::value <= object_category::wrapper_value,
1540 detail::enabler> = detail::dummy>
1541bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1542 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1547template <
typename AssignTo,
1549 enable_if_t<(type_count<AssignTo>::value <= 2) && expected_count<AssignTo>::value == 1 &&
1550 is_tuple_like<ConvertTo>::value && type_count_base<ConvertTo>::value == 2,
1551 detail::enabler> = detail::dummy>
1552bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1554 using FirstType =
typename std::remove_const<typename std::tuple_element<0, ConvertTo>::type>::type;
1555 using SecondType =
typename std::tuple_element<1, ConvertTo>::type;
1558 bool retval = lexical_assign<FirstType, FirstType>(strings[0], v1);
1559 retval = retval && lexical_assign<SecondType, SecondType>((strings.size() > 1) ? strings[1] : std::string{}, v2);
1561 output = AssignTo{v1, v2};
1567template <
class AssignTo,
1569 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1570 type_count<ConvertTo>::value == 1,
1571 detail::enabler> = detail::dummy>
1572bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1573 output.erase(output.begin(), output.end());
1574 if(strings.empty()) {
1577 if(strings.size() == 1 && strings[0] ==
"{}") {
1580 bool skip_remaining =
false;
1581 if(strings.size() == 2 && strings[0] ==
"{}" && is_separator(strings[1])) {
1582 skip_remaining =
true;
1584 for(
const auto &elem : strings) {
1585 typename AssignTo::value_type out;
1586 bool retval = lexical_assign<typename AssignTo::value_type, typename ConvertTo::value_type>(elem, out);
1590 output.insert(output.end(), std::move(out));
1591 if(skip_remaining) {
1595 return (!output.empty());
1599template <class AssignTo, class ConvertTo, enable_if_t<is_complex<ConvertTo>::value, detail::enabler> = detail::dummy>
1600bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1602 if(strings.size() >= 2 && !strings[1].empty()) {
1603 using XC2 =
typename wrapped_type<ConvertTo, double>::type;
1605 auto str1 = strings[1];
1606 if(str1.back() ==
'i' || str1.back() ==
'j') {
1609 auto worked = lexical_cast(strings[0], x) && lexical_cast(str1, y);
1611 output = ConvertTo{x, y};
1615 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1619template <
class AssignTo,
1621 enable_if_t<is_mutable_container<AssignTo>::value && (expected_count<ConvertTo>::value == 1) &&
1622 (type_count<ConvertTo>::value == 1),
1623 detail::enabler> = detail::dummy>
1624bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1627 output.reserve(strings.size());
1628 for(
const auto &elem : strings) {
1630 output.emplace_back();
1631 retval = retval && lexical_assign<typename AssignTo::value_type, ConvertTo>(elem, output.back());
1633 return (!output.empty()) && retval;
1639template <
class AssignTo,
1641 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1642 type_count_base<ConvertTo>::value == 2,
1643 detail::enabler> = detail::dummy>
1644bool lexical_conversion(std::vector<std::string> strings, AssignTo &output);
1647template <
class AssignTo,
1649 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1650 type_count_base<ConvertTo>::value != 2 &&
1651 ((type_count<ConvertTo>::value > 2) ||
1652 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1653 detail::enabler> = detail::dummy>
1654bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1657template <
class AssignTo,
1659 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1660 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1661 type_count<ConvertTo>::value > 2),
1662 detail::enabler> = detail::dummy>
1663bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1667template <
typename AssignTo,
1669 enable_if_t<!is_tuple_like<AssignTo>::value && !is_mutable_container<AssignTo>::value &&
1670 classify_object<ConvertTo>::value != object_category::wrapper_value &&
1671 (is_mutable_container<ConvertTo>::value || type_count<ConvertTo>::value > 2),
1672 detail::enabler> = detail::dummy>
1673bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1675 if(strings.size() > 1 || (!strings.empty() && !(strings.front().empty()))) {
1677 auto retval = lexical_conversion<ConvertTo, ConvertTo>(strings, val);
1678 output = AssignTo{val};
1681 output = AssignTo{};
1686template <
class AssignTo,
class ConvertTo, std::
size_t I>
1687inline typename std::enable_if<(I >= type_count_base<AssignTo>::value),
bool>::type
1688tuple_conversion(
const std::vector<std::string> &, AssignTo &) {
1693template <
class AssignTo,
class ConvertTo>
1694inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && type_count<ConvertTo>::value == 1,
bool>::type
1695tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1696 auto retval = lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1697 strings.erase(strings.begin());
1702template <
class AssignTo,
class ConvertTo>
1703inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && (type_count<ConvertTo>::value > 1) &&
1704 type_count<ConvertTo>::value == type_count_min<ConvertTo>::value,
1706tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1707 auto retval = lexical_conversion<AssignTo, ConvertTo>(strings, output);
1708 strings.erase(strings.begin(), strings.begin() + type_count<ConvertTo>::value);
1713template <
class AssignTo,
class ConvertTo>
1714inline typename std::enable_if<is_mutable_container<ConvertTo>::value ||
1715 type_count<ConvertTo>::value != type_count_min<ConvertTo>::value,
1717tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1719 std::size_t index{subtype_count_min<ConvertTo>::value};
1720 const std::size_t mx_count{subtype_count<ConvertTo>::value};
1721 const std::size_t mx{(std::min)(mx_count, strings.size() - 1)};
1724 if(is_separator(strings[index])) {
1729 bool retval = lexical_conversion<AssignTo, ConvertTo>(
1730 std::vector<std::string>(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index)), output);
1731 if(strings.size() > index) {
1732 strings.erase(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index) + 1);
1740template <
class AssignTo,
class ConvertTo, std::
size_t I>
1741inline typename std::enable_if<(I < type_count_base<AssignTo>::value),
bool>::type
1742tuple_conversion(std::vector<std::string> strings, AssignTo &output) {
1744 using ConvertToElement =
typename std::
1745 conditional<is_tuple_like<ConvertTo>::value,
typename std::tuple_element<I, ConvertTo>::type, ConvertTo>::type;
1746 if(!strings.empty()) {
1747 retval = retval && tuple_type_conversion<typename std::tuple_element<I, AssignTo>::type, ConvertToElement>(
1748 strings, std::get<I>(output));
1750 retval = retval && tuple_conversion<AssignTo, ConvertTo, I + 1>(std::move(strings), output);
1755template <
class AssignTo,
1757 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1758 type_count_base<ConvertTo>::value == 2,
1760bool lexical_conversion(std::vector<std::string> strings, AssignTo &output) {
1762 while(!strings.empty()) {
1764 typename std::remove_const<typename std::tuple_element<0, typename ConvertTo::value_type>::type>::type v1{};
1765 typename std::tuple_element<1, typename ConvertTo::value_type>::type v2{};
1766 bool retval = tuple_type_conversion<decltype(v1), decltype(v1)>(strings, v1);
1767 if(!strings.empty()) {
1768 retval = retval && tuple_type_conversion<decltype(v2), decltype(v2)>(strings, v2);
1774 output.insert(output.end(),
typename AssignTo::value_type{v1, v2});
1779 return (!output.empty());
1783template <
class AssignTo,
1785 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1786 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1787 type_count<ConvertTo>::value > 2),
1789bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1791 !is_tuple_like<ConvertTo>::value || type_count_base<AssignTo>::value == type_count_base<ConvertTo>::value,
1792 "if the conversion type is defined as a tuple it must be the same size as the type you are converting to");
1793 return tuple_conversion<AssignTo, ConvertTo, 0>(strings, output);
1797template <
class AssignTo,
1799 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1800 type_count_base<ConvertTo>::value != 2 &&
1801 ((type_count<ConvertTo>::value > 2) ||
1802 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1804bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1807 std::vector<std::string> temp;
1809 std::size_t icount{0};
1810 std::size_t xcm{type_count<ConvertTo>::value};
1811 auto ii_max = strings.size();
1812 while(ii < ii_max) {
1813 temp.push_back(strings[ii]);
1816 if(icount == xcm || is_separator(temp.back()) || ii == ii_max) {
1817 if(
static_cast<int>(xcm) > type_count_min<ConvertTo>::value && is_separator(temp.back())) {
1820 typename AssignTo::value_type temp_out;
1822 lexical_conversion<typename AssignTo::value_type, typename ConvertTo::value_type>(temp, temp_out);
1827 output.insert(output.end(), std::move(temp_out));
1835template <
typename AssignTo,
1837 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1838 std::is_assignable<ConvertTo &, ConvertTo>::value,
1839 detail::enabler> = detail::dummy>
1840bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1841 if(strings.empty() || strings.front().empty()) {
1842 output = ConvertTo{};
1845 typename ConvertTo::value_type val;
1846 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1847 output = ConvertTo{val};
1854template <
typename AssignTo,
1856 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1857 !std::is_assignable<AssignTo &, ConvertTo>::value,
1858 detail::enabler> = detail::dummy>
1859bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1860 using ConvertType =
typename ConvertTo::value_type;
1861 if(strings.empty() || strings.front().empty()) {
1862 output = ConvertType{};
1866 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1874inline std::string sum_string_vector(
const std::vector<std::string> &values) {
1877 std::int64_t ival{0};
1879 for(
const auto &arg : values) {
1881 if(!integral_conversion(arg, tv)) {
1886 if((tv > 0 && ival > (std::numeric_limits<std::int64_t>::max)() - tv) ||
1887 (tv < 0 && ival < (std::numeric_limits<std::int64_t>::min)() - tv)) {
1894 return std::to_string(ival);
1900 for(
const auto &arg : values) {
1902 auto comp = lexical_cast(arg, tv);
1905 auto fv = detail::to_flag_value(arg);
1906 fail = (errno != 0);
1910 tv =
static_cast<double>(fv);
1915 for(
const auto &arg : values) {
1919 std::ostringstream out;
Definition TypeTools.hpp:96
Check for complex.
Definition TypeTools.hpp:235
Definition TypeTools.hpp:177
Check for input streamability.
Definition TypeTools.hpp:224
Definition TypeTools.hpp:213
Definition TypeTools.hpp:299
This can be specialized to override the type deduction for IsMember.
Definition TypeTools.hpp:81
not a pointer
Definition TypeTools.hpp:115
Definition TypeTools.hpp:125
Definition TypeTools.hpp:260
Definition TypeTools.hpp:280
Definition TypeTools.hpp:291
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:157
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:161
Adaptor for set-like structure: This just wraps a normal container in a few utilities that do almost ...
Definition TypeTools.hpp:130
static auto second(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the second value (really just the underlying value)
Definition TypeTools.hpp:140
static auto first(Q &&pair_value) -> decltype(std::forward< Q >(pair_value))
Get the first value (really just the underlying value)
Definition TypeTools.hpp:136
forward declare the subtype_count_min structure
Definition TypeTools.hpp:501
Set of overloads to get the type size of an object.
Definition TypeTools.hpp:498
This will only trigger for actual void type.
Definition TypeTools.hpp:311
This will only trigger for actual void type.
Definition TypeTools.hpp:504
template to get the underlying value type if it exists or use a default
Definition TypeTools.hpp:486
Check to see if something is bool (fail check by default)
Definition TypeTools.hpp:61
Check to see if something is copyable pointer.
Definition TypeTools.hpp:76
Check to see if something is a shared pointer.
Definition TypeTools.hpp:67
A copy of std::void_t from C++17 (helper for C++11 and C++14)
Definition TypeTools.hpp:50