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 {
947 if(input.empty() || input.front() ==
'-') {
952 std::uint64_t output_ll = std::strtoull(input.c_str(), &val, 0);
953 if(errno == ERANGE) {
956 output =
static_cast<T
>(output_ll);
957 if(val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll) {
961 std::int64_t output_sll = std::strtoll(input.c_str(), &val, 0);
962 if(val == (input.c_str() + input.size())) {
963 output = (output_sll < 0) ? static_cast<T>(0) : static_cast<T>(output_sll);
964 return (
static_cast<std::int64_t
>(output) == output_sll);
967 auto group_separators = get_group_separators();
968 if(input.find_first_of(group_separators) != std::string::npos) {
969 std::string nstring = input;
970 for(
auto &separator : group_separators) {
971 if(input.find_first_of(separator) != std::string::npos) {
972 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
975 return integral_conversion(nstring, output);
978 if(std::isspace(
static_cast<unsigned char>(input.back()))) {
979 return integral_conversion(trim_copy(input), output);
981 if(input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0) {
984 output_ll = std::strtoull(input.c_str() + 2, &val, 8);
985 if(errno == ERANGE) {
988 output =
static_cast<T
>(output_ll);
989 return (val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll);
991 if(input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0) {
997 output_ll = std::strtoull(input.c_str() + 2, &val, 2);
998 if(errno == ERANGE) {
1001 output =
static_cast<T
>(output_ll);
1002 return (val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll);
1009template <typename T, enable_if_t<std::is_signed<T>::value, detail::enabler> = detail::dummy>
1010bool integral_conversion(
const std::string &input, T &output)
noexcept {
1014 char *val =
nullptr;
1016 std::int64_t output_ll = std::strtoll(input.c_str(), &val, 0);
1017 if(errno == ERANGE) {
1020 output =
static_cast<T
>(output_ll);
1021 if(val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll) {
1024 if(input ==
"true") {
1026 output =
static_cast<T
>(1);
1030 auto group_separators = get_group_separators();
1031 if(input.find_first_of(group_separators) != std::string::npos) {
1032 for(
auto &separator : group_separators) {
1033 if(input.find_first_of(separator) != std::string::npos) {
1034 std::string nstring = input;
1035 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1036 return integral_conversion(nstring, output);
1040 if(std::isspace(
static_cast<unsigned char>(input.back()))) {
1041 return integral_conversion(trim_copy(input), output);
1043 if(input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0) {
1046 output_ll = std::strtoll(input.c_str() + 2, &val, 8);
1047 if(errno == ERANGE) {
1050 output =
static_cast<T
>(output_ll);
1051 return (val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll);
1053 if(input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0) {
1059 output_ll = std::strtoll(input.c_str() + 2, &val, 2);
1060 if(errno == ERANGE) {
1063 output =
static_cast<T
>(output_ll);
1064 return (val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll);
1071inline std::int64_t to_flag_value(std::string val)
noexcept {
1072 static const std::string trueString(
"true");
1073 static const std::string falseString(
"false");
1074 if(val == trueString) {
1077 if(val == falseString) {
1080 val = detail::to_lower(val);
1081 std::int64_t ret = 0;
1082 if(val.size() == 1) {
1083 if(val[0] >=
'1' && val[0] <=
'9') {
1084 return (
static_cast<std::int64_t
>(val[0]) -
'0');
1104 if(val == trueString || val ==
"on" || val ==
"yes" || val ==
"enable") {
1106 }
else if(val == falseString || val ==
"off" || val ==
"no" || val ==
"disable") {
1109 char *loc_ptr{
nullptr};
1110 ret = std::strtoll(val.c_str(), &loc_ptr, 0);
1111 if(loc_ptr != (val.c_str() + val.size()) && errno == 0) {
1119template <
typename T,
1120 enable_if_t<classify_object<T>::value == object_category::integral_value ||
1121 classify_object<T>::value == object_category::unsigned_integral,
1122 detail::enabler> = detail::dummy>
1123bool lexical_cast(
const std::string &input, T &output) {
1124 return integral_conversion(input, output);
1128template <
typename T,
1129 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> = detail::dummy>
1130bool lexical_cast(
const std::string &input, T &output) {
1131 if(input.size() == 1) {
1132 output =
static_cast<T
>(input[0]);
1138 bool result = integral_conversion(input, res);
1140 output =
static_cast<T
>(res);
1146template <
typename T,
1147 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
1148bool lexical_cast(
const std::string &input, T &output) {
1150 auto out = to_flag_value(input);
1153 }
else if(errno == ERANGE) {
1154 output = (input[0] !=
'-');
1162template <
typename T,
1163 enable_if_t<classify_object<T>::value == object_category::floating_point, detail::enabler> = detail::dummy>
1164bool lexical_cast(
const std::string &input, T &output) {
1168 char *val =
nullptr;
1169 auto output_ld = std::strtold(input.c_str(), &val);
1170 output =
static_cast<T
>(output_ld);
1171 if(val == (input.c_str() + input.size())) {
1174 while(std::isspace(
static_cast<unsigned char>(*val))) {
1176 if(val == (input.c_str() + input.size())) {
1182 auto group_separators = get_group_separators();
1183 if(input.find_first_of(group_separators) != std::string::npos) {
1184 for(
auto &separator : group_separators) {
1185 if(input.find_first_of(separator) != std::string::npos) {
1186 std::string nstring = input;
1187 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1188 return lexical_cast(nstring, output);
1196template <
typename T,
1197 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
1198bool lexical_cast(
const std::string &input, T &output) {
1199 using XC =
typename wrapped_type<T, double>::type;
1202 bool worked =
false;
1203 auto nloc = str1.find_last_of(
"+-");
1204 if(nloc != std::string::npos && nloc > 0) {
1205 worked = lexical_cast(str1.substr(0, nloc), x);
1206 str1 = str1.substr(nloc);
1207 if(str1.back() ==
'i' || str1.back() ==
'j')
1209 worked = worked && lexical_cast(str1, y);
1211 if(str1.back() ==
'i' || str1.back() ==
'j') {
1213 worked = lexical_cast(str1, y);
1216 worked = lexical_cast(str1, x);
1224 return from_stream(input, output);
1228template <
typename T,
1229 enable_if_t<classify_object<T>::value == object_category::string_assignable, detail::enabler> = detail::dummy>
1230bool lexical_cast(
const std::string &input, T &output) {
1238 enable_if_t<classify_object<T>::value == object_category::string_constructible, detail::enabler> = detail::dummy>
1239bool lexical_cast(
const std::string &input, T &output) {
1247 enable_if_t<classify_object<T>::value == object_category::wstring_assignable, detail::enabler> = detail::dummy>
1248bool lexical_cast(
const std::string &input, T &output) {
1249 output = widen(input);
1255 enable_if_t<classify_object<T>::value == object_category::wstring_constructible, detail::enabler> = detail::dummy>
1256bool lexical_cast(
const std::string &input, T &output) {
1257 output = T{widen(input)};
1262template <
typename T,
1263 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
1264bool lexical_cast(
const std::string &input, T &output) {
1265 typename std::underlying_type<T>::type val;
1266 if(!integral_conversion(input, val)) {
1269 output =
static_cast<T
>(val);
1274template <
typename T,
1275 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1276 std::is_assignable<T &, typename T::value_type>::value,
1277 detail::enabler> = detail::dummy>
1278bool lexical_cast(
const std::string &input, T &output) {
1279 typename T::value_type val;
1280 if(lexical_cast(input, val)) {
1284 return from_stream(input, output);
1287template <
typename T,
1288 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1289 !std::is_assignable<T &, typename T::value_type>::value && std::is_assignable<T &, T>::value,
1290 detail::enabler> = detail::dummy>
1291bool lexical_cast(
const std::string &input, T &output) {
1292 typename T::value_type val;
1293 if(lexical_cast(input, val)) {
1297 return from_stream(input, output);
1303 enable_if_t<classify_object<T>::value == object_category::number_constructible, detail::enabler> = detail::dummy>
1304bool lexical_cast(
const std::string &input, T &output) {
1306 if(integral_conversion(input, val)) {
1312 if(lexical_cast(input, dval)) {
1317 return from_stream(input, output);
1323 enable_if_t<classify_object<T>::value == object_category::integer_constructible, detail::enabler> = detail::dummy>
1324bool lexical_cast(
const std::string &input, T &output) {
1326 if(integral_conversion(input, val)) {
1330 return from_stream(input, output);
1336 enable_if_t<classify_object<T>::value == object_category::double_constructible, detail::enabler> = detail::dummy>
1337bool lexical_cast(
const std::string &input, T &output) {
1339 if(lexical_cast(input, val)) {
1343 return from_stream(input, output);
1347template <
typename T,
1348 enable_if_t<classify_object<T>::value == object_category::other && std::is_assignable<T &, int>::value,
1349 detail::enabler> = detail::dummy>
1350bool lexical_cast(
const std::string &input, T &output) {
1352 if(integral_conversion(input, val)) {
1354#pragma warning(push)
1355#pragma warning(disable : 4800)
1368 return from_stream(input, output);
1373template <
typename T,
1374 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1375 is_istreamable<T>::value,
1376 detail::enabler> = detail::dummy>
1377bool lexical_cast(
const std::string &input, T &output) {
1378 return from_stream(input, output);
1383template <
typename T,
1384 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1385 !is_istreamable<T>::value && !adl_detail::is_lexical_castable<T>::value,
1386 detail::enabler> = detail::dummy>
1387bool lexical_cast(
const std::string & , T & ) {
1388 static_assert(!std::is_same<T, T>::value,
1389 "option object type must have a lexical cast overload or streaming input operator(>>) defined, if it "
1390 "is convertible from another type use the add_option<T, XC>(...) with XC being the known type");
1396template <
typename AssignTo,
1398 enable_if_t<std::is_same<AssignTo, ConvertTo>::value &&
1399 (classify_object<AssignTo>::value == object_category::string_assignable ||
1400 classify_object<AssignTo>::value == object_category::string_constructible ||
1401 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1402 classify_object<AssignTo>::value == object_category::wstring_constructible),
1403 detail::enabler> = detail::dummy>
1404bool lexical_assign(
const std::string &input, AssignTo &output) {
1405 return lexical_cast(input, output);
1409template <
typename AssignTo,
1411 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, AssignTo>::value &&
1412 classify_object<AssignTo>::value != object_category::string_assignable &&
1413 classify_object<AssignTo>::value != object_category::string_constructible &&
1414 classify_object<AssignTo>::value != object_category::wstring_assignable &&
1415 classify_object<AssignTo>::value != object_category::wstring_constructible,
1416 detail::enabler> = detail::dummy>
1417bool lexical_assign(
const std::string &input, AssignTo &output) {
1419 output = AssignTo{};
1423 return lexical_cast(input, output);
1427template <
typename AssignTo,
1429 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1430 classify_object<AssignTo>::value == object_category::wrapper_value,
1431 detail::enabler> = detail::dummy>
1432bool lexical_assign(
const std::string &input, AssignTo &output) {
1434 typename AssignTo::value_type emptyVal{};
1438 return lexical_cast(input, output);
1443template <
typename AssignTo,
1445 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1446 classify_object<AssignTo>::value != object_category::wrapper_value &&
1447 std::is_assignable<AssignTo &, int>::value,
1448 detail::enabler> = detail::dummy>
1449bool lexical_assign(
const std::string &input, AssignTo &output) {
1455 if(lexical_cast(input, val)) {
1456#if defined(__clang__)
1458#pragma clang diagnostic push
1459#pragma clang diagnostic ignored "-Wsign-conversion"
1462#if defined(__clang__)
1463#pragma clang diagnostic pop
1471template <
typename AssignTo,
1473 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, ConvertTo &>::value,
1474 detail::enabler> = detail::dummy>
1475bool lexical_assign(
const std::string &input, AssignTo &output) {
1477 bool parse_result = (!input.empty()) ? lexical_cast(input, val) : true;
1481 return parse_result;
1488 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, ConvertTo &>::value &&
1489 std::is_move_assignable<AssignTo>::value,
1490 detail::enabler> = detail::dummy>
1491bool lexical_assign(
const std::string &input, AssignTo &output) {
1493 bool parse_result = input.empty() ? true : lexical_cast(input, val);
1495 output = AssignTo(val);
1497 return parse_result;
1501template <
typename AssignTo,
1503 enable_if_t<classify_object<ConvertTo>::value <= object_category::other &&
1504 classify_object<AssignTo>::value <= object_category::wrapper_value,
1505 detail::enabler> = detail::dummy>
1506bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1507 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1512template <
typename AssignTo,
1514 enable_if_t<(type_count<AssignTo>::value <= 2) && expected_count<AssignTo>::value == 1 &&
1515 is_tuple_like<ConvertTo>::value && type_count_base<ConvertTo>::value == 2,
1516 detail::enabler> = detail::dummy>
1517bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1519 using FirstType =
typename std::remove_const<typename std::tuple_element<0, ConvertTo>::type>::type;
1520 using SecondType =
typename std::tuple_element<1, ConvertTo>::type;
1523 bool retval = lexical_assign<FirstType, FirstType>(strings[0], v1);
1524 retval = retval && lexical_assign<SecondType, SecondType>((strings.size() > 1) ? strings[1] : std::string{}, v2);
1526 output = AssignTo{v1, v2};
1532template <
class AssignTo,
1534 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1535 type_count<ConvertTo>::value == 1,
1536 detail::enabler> = detail::dummy>
1537bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1538 output.erase(output.begin(), output.end());
1539 if(strings.empty()) {
1542 if(strings.size() == 1 && strings[0] ==
"{}") {
1545 bool skip_remaining =
false;
1546 if(strings.size() == 2 && strings[0] ==
"{}" && is_separator(strings[1])) {
1547 skip_remaining =
true;
1549 for(
const auto &elem : strings) {
1550 typename AssignTo::value_type out;
1551 bool retval = lexical_assign<typename AssignTo::value_type, typename ConvertTo::value_type>(elem, out);
1555 output.insert(output.end(), std::move(out));
1556 if(skip_remaining) {
1560 return (!output.empty());
1564template <class AssignTo, class ConvertTo, enable_if_t<is_complex<ConvertTo>::value, detail::enabler> = detail::dummy>
1565bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1567 if(strings.size() >= 2 && !strings[1].empty()) {
1568 using XC2 =
typename wrapped_type<ConvertTo, double>::type;
1570 auto str1 = strings[1];
1571 if(str1.back() ==
'i' || str1.back() ==
'j') {
1574 auto worked = lexical_cast(strings[0], x) && lexical_cast(str1, y);
1576 output = ConvertTo{x, y};
1580 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1584template <
class AssignTo,
1586 enable_if_t<is_mutable_container<AssignTo>::value && (expected_count<ConvertTo>::value == 1) &&
1587 (type_count<ConvertTo>::value == 1),
1588 detail::enabler> = detail::dummy>
1589bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1592 output.reserve(strings.size());
1593 for(
const auto &elem : strings) {
1595 output.emplace_back();
1596 retval = retval && lexical_assign<typename AssignTo::value_type, ConvertTo>(elem, output.back());
1598 return (!output.empty()) && retval;
1604template <
class AssignTo,
1606 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1607 type_count_base<ConvertTo>::value == 2,
1608 detail::enabler> = detail::dummy>
1609bool lexical_conversion(std::vector<std::string> strings, AssignTo &output);
1612template <
class AssignTo,
1614 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1615 type_count_base<ConvertTo>::value != 2 &&
1616 ((type_count<ConvertTo>::value > 2) ||
1617 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1618 detail::enabler> = detail::dummy>
1619bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1622template <
class AssignTo,
1624 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1625 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1626 type_count<ConvertTo>::value > 2),
1627 detail::enabler> = detail::dummy>
1628bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1632template <
typename AssignTo,
1634 enable_if_t<!is_tuple_like<AssignTo>::value && !is_mutable_container<AssignTo>::value &&
1635 classify_object<ConvertTo>::value != object_category::wrapper_value &&
1636 (is_mutable_container<ConvertTo>::value || type_count<ConvertTo>::value > 2),
1637 detail::enabler> = detail::dummy>
1638bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1640 if(strings.size() > 1 || (!strings.empty() && !(strings.front().empty()))) {
1642 auto retval = lexical_conversion<ConvertTo, ConvertTo>(strings, val);
1643 output = AssignTo{val};
1646 output = AssignTo{};
1651template <
class AssignTo,
class ConvertTo, std::
size_t I>
1652inline typename std::enable_if<(I >= type_count_base<AssignTo>::value),
bool>::type
1653tuple_conversion(
const std::vector<std::string> &, AssignTo &) {
1658template <
class AssignTo,
class ConvertTo>
1659inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && type_count<ConvertTo>::value == 1,
bool>::type
1660tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1661 auto retval = lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1662 strings.erase(strings.begin());
1667template <
class AssignTo,
class ConvertTo>
1668inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && (type_count<ConvertTo>::value > 1) &&
1669 type_count<ConvertTo>::value == type_count_min<ConvertTo>::value,
1671tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1672 auto retval = lexical_conversion<AssignTo, ConvertTo>(strings, output);
1673 strings.erase(strings.begin(), strings.begin() + type_count<ConvertTo>::value);
1678template <
class AssignTo,
class ConvertTo>
1679inline typename std::enable_if<is_mutable_container<ConvertTo>::value ||
1680 type_count<ConvertTo>::value != type_count_min<ConvertTo>::value,
1682tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1684 std::size_t index{subtype_count_min<ConvertTo>::value};
1685 const std::size_t mx_count{subtype_count<ConvertTo>::value};
1686 const std::size_t mx{(std::min)(mx_count, strings.size() - 1)};
1689 if(is_separator(strings[index])) {
1694 bool retval = lexical_conversion<AssignTo, ConvertTo>(
1695 std::vector<std::string>(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index)), output);
1696 if(strings.size() > index) {
1697 strings.erase(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index) + 1);
1705template <
class AssignTo,
class ConvertTo, std::
size_t I>
1706inline typename std::enable_if<(I < type_count_base<AssignTo>::value),
bool>::type
1707tuple_conversion(std::vector<std::string> strings, AssignTo &output) {
1709 using ConvertToElement =
typename std::
1710 conditional<is_tuple_like<ConvertTo>::value,
typename std::tuple_element<I, ConvertTo>::type, ConvertTo>::type;
1711 if(!strings.empty()) {
1712 retval = retval && tuple_type_conversion<typename std::tuple_element<I, AssignTo>::type, ConvertToElement>(
1713 strings, std::get<I>(output));
1715 retval = retval && tuple_conversion<AssignTo, ConvertTo, I + 1>(std::move(strings), output);
1720template <
class AssignTo,
1722 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1723 type_count_base<ConvertTo>::value == 2,
1725bool lexical_conversion(std::vector<std::string> strings, AssignTo &output) {
1727 while(!strings.empty()) {
1729 typename std::remove_const<typename std::tuple_element<0, typename ConvertTo::value_type>::type>::type v1;
1730 typename std::tuple_element<1, typename ConvertTo::value_type>::type v2;
1731 bool retval = tuple_type_conversion<decltype(v1), decltype(v1)>(strings, v1);
1732 if(!strings.empty()) {
1733 retval = retval && tuple_type_conversion<decltype(v2), decltype(v2)>(strings, v2);
1736 output.insert(output.end(),
typename AssignTo::value_type{v1, v2});
1741 return (!output.empty());
1745template <
class AssignTo,
1747 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1748 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1749 type_count<ConvertTo>::value > 2),
1751bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1753 !is_tuple_like<ConvertTo>::value || type_count_base<AssignTo>::value == type_count_base<ConvertTo>::value,
1754 "if the conversion type is defined as a tuple it must be the same size as the type you are converting to");
1755 return tuple_conversion<AssignTo, ConvertTo, 0>(strings, output);
1759template <
class AssignTo,
1761 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1762 type_count_base<ConvertTo>::value != 2 &&
1763 ((type_count<ConvertTo>::value > 2) ||
1764 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1766bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1769 std::vector<std::string> temp;
1771 std::size_t icount{0};
1772 std::size_t xcm{type_count<ConvertTo>::value};
1773 auto ii_max = strings.size();
1774 while(ii < ii_max) {
1775 temp.push_back(strings[ii]);
1778 if(icount == xcm || is_separator(temp.back()) || ii == ii_max) {
1779 if(
static_cast<int>(xcm) > type_count_min<ConvertTo>::value && is_separator(temp.back())) {
1782 typename AssignTo::value_type temp_out;
1784 lexical_conversion<typename AssignTo::value_type, typename ConvertTo::value_type>(temp, temp_out);
1789 output.insert(output.end(), std::move(temp_out));
1797template <
typename AssignTo,
1799 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1800 std::is_assignable<ConvertTo &, ConvertTo>::value,
1801 detail::enabler> = detail::dummy>
1802bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1803 if(strings.empty() || strings.front().empty()) {
1804 output = ConvertTo{};
1807 typename ConvertTo::value_type val;
1808 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1809 output = ConvertTo{val};
1816template <
typename AssignTo,
1818 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1819 !std::is_assignable<AssignTo &, ConvertTo>::value,
1820 detail::enabler> = detail::dummy>
1821bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1822 using ConvertType =
typename ConvertTo::value_type;
1823 if(strings.empty() || strings.front().empty()) {
1824 output = ConvertType{};
1828 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1836inline std::string sum_string_vector(
const std::vector<std::string> &values) {
1840 for(
const auto &arg : values) {
1842 auto comp = lexical_cast(arg, tv);
1845 auto fv = detail::to_flag_value(arg);
1846 fail = (errno != 0);
1850 tv =
static_cast<double>(fv);
1855 for(
const auto &arg : values) {
1859 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