24#include "Encoding.hpp"
25#include "StringTools.hpp"
36enum class enabler : std::uint8_t {};
39constexpr 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>();
547template <
typename T>
struct type_count<T, typename std::enable_if<is_tuple_like<T>::value>::type> {
548 static constexpr int value{tuple_type_size<T, 0>()};
552template <
typename T>
struct subtype_count {
553 static constexpr int value{is_mutable_container<T>::value ? expected_max_vector_size : type_count<T>::value};
557template <
typename T,
typename Enable =
void>
struct type_count_min {
558 static const int value{0};
563struct type_count_min<
565 typename std::enable_if<!is_mutable_container<T>::value && !is_tuple_like<T>::value && !is_wrapper<T>::value &&
566 !is_complex<T>::value && !std::is_void<T>::value>::type> {
567 static constexpr int value{type_count<T>::value};
571template <
typename T>
struct type_count_min<T, typename std::enable_if<is_complex<T>::value>::type> {
572 static constexpr int value{1};
577struct type_count_min<
579 typename std::enable_if<is_wrapper<T>::value && !is_complex<T>::value && !is_tuple_like<T>::value>::type> {
580 static constexpr int value{subtype_count_min<typename T::value_type>::value};
584template <
typename T, std::
size_t I>
585constexpr typename std::enable_if<I == type_count_base<T>::value,
int>::type tuple_type_size_min() {
590template <
typename T, std::
size_t I>
591 constexpr typename std::enable_if < I<type_count_base<T>::value,
int>::type tuple_type_size_min() {
592 return subtype_count_min<typename std::tuple_element<I, T>::type>::value + tuple_type_size_min<T, I + 1>();
596template <
typename T>
struct type_count_min<T, typename std::enable_if<is_tuple_like<T>::value>::type> {
597 static constexpr int value{tuple_type_size_min<T, 0>()};
601template <
typename T>
struct subtype_count_min {
602 static constexpr int value{is_mutable_container<T>::value
603 ? ((type_count<T>::value < expected_max_vector_size) ? type_count<T>::value : 0)
604 : type_count_min<T>::value};
608template <
typename T,
typename Enable =
void>
struct expected_count {
609 static const int value{0};
614struct expected_count<T,
615 typename std::enable_if<!is_mutable_container<T>::value && !is_wrapper<T>::value &&
616 !std::is_void<T>::value>::type> {
617 static constexpr int value{1};
620template <
typename T>
struct expected_count<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
621 static constexpr int value{expected_max_vector_size};
626struct expected_count<T, typename std::enable_if<!is_mutable_container<T>::value && is_wrapper<T>::value>::type> {
627 static constexpr int value{expected_count<typename T::value_type>::value};
631enum class object_category : std::uint8_t {
634 unsigned_integral = 4,
638 number_constructible = 12,
639 double_constructible = 14,
640 integer_constructible = 16,
642 string_assignable = 23,
643 string_constructible = 24,
644 wstring_assignable = 25,
645 wstring_constructible = 26,
651 container_value = 80,
658template <
typename T,
typename Enable =
void>
struct classify_object {
659 static constexpr object_category value{object_category::other};
664struct classify_object<
666 typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, char>::value && std::is_signed<T>::value &&
667 !is_bool<T>::value && !std::is_enum<T>::value>::type> {
668 static constexpr object_category value{object_category::integral_value};
673struct classify_object<T,
674 typename std::enable_if<std::is_integral<T>::value && std::is_unsigned<T>::value &&
675 !std::is_same<T, char>::value && !is_bool<T>::value>::type> {
676 static constexpr object_category value{object_category::unsigned_integral};
681struct classify_object<T, typename std::enable_if<std::is_same<T, char>::value && !std::is_enum<T>::value>::type> {
682 static constexpr object_category value{object_category::char_value};
686template <
typename T>
struct classify_object<T, typename std::enable_if<is_bool<T>::value>::type> {
687 static constexpr object_category value{object_category::boolean_value};
691template <
typename T>
struct classify_object<T, typename std::enable_if<std::is_floating_point<T>::value>::type> {
692 static constexpr object_category value{object_category::floating_point};
697#define WIDE_STRING_CHECK \
698 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value
699#define STRING_CHECK true
701#define WIDE_STRING_CHECK true
702#define STRING_CHECK !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value
707struct classify_object<
709 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value && WIDE_STRING_CHECK &&
710 std::is_assignable<T &, std::string>::value>::type> {
711 static constexpr object_category value{object_category::string_assignable};
716struct classify_object<
718 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
719 !std::is_assignable<T &, std::string>::value && (type_count<T>::value == 1) &&
720 WIDE_STRING_CHECK && std::is_constructible<T, std::string>::value>::type> {
721 static constexpr object_category value{object_category::string_constructible};
726struct classify_object<T,
727 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
728 STRING_CHECK && std::is_assignable<T &, std::wstring>::value>::type> {
729 static constexpr object_category value{object_category::wstring_assignable};
733struct classify_object<
735 typename std::enable_if<!std::is_floating_point<T>::value && !std::is_integral<T>::value &&
736 !std::is_assignable<T &, std::wstring>::value && (type_count<T>::value == 1) &&
737 STRING_CHECK && std::is_constructible<T, std::wstring>::value>::type> {
738 static constexpr object_category value{object_category::wstring_constructible};
742template <
typename T>
struct classify_object<T, typename std::enable_if<std::is_enum<T>::value>::type> {
743 static constexpr object_category value{object_category::enumeration};
746template <
typename T>
struct classify_object<T, typename std::enable_if<is_complex<T>::value>::type> {
747 static constexpr object_category value{object_category::complex_number};
752template <
typename T>
struct uncommon_type {
753 using type =
typename std::conditional<
754 !std::is_floating_point<T>::value && !std::is_integral<T>::value &&
755 !std::is_assignable<T &, std::string>::value && !std::is_constructible<T, std::string>::value &&
756 !std::is_assignable<T &, std::wstring>::value && !std::is_constructible<T, std::wstring>::value &&
757 !is_complex<T>::value && !is_mutable_container<T>::value && !std::is_enum<T>::value,
759 std::false_type>::type;
760 static constexpr bool value = type::value;
765struct classify_object<T,
766 typename std::enable_if<(!is_mutable_container<T>::value && is_wrapper<T>::value &&
767 !is_tuple_like<T>::value && uncommon_type<T>::value)>::type> {
768 static constexpr object_category value{object_category::wrapper_value};
773struct classify_object<T,
774 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
775 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
776 is_direct_constructible<T, int>::value>::type> {
777 static constexpr object_category value{object_category::number_constructible};
782struct classify_object<T,
783 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
784 !is_wrapper<T>::value && !is_direct_constructible<T, double>::value &&
785 is_direct_constructible<T, int>::value>::type> {
786 static constexpr object_category value{object_category::integer_constructible};
791struct classify_object<T,
792 typename std::enable_if<uncommon_type<T>::value && type_count<T>::value == 1 &&
793 !is_wrapper<T>::value && is_direct_constructible<T, double>::value &&
794 !is_direct_constructible<T, int>::value>::type> {
795 static constexpr object_category value{object_category::double_constructible};
800struct classify_object<
802 typename std::enable_if<is_tuple_like<T>::value &&
803 ((type_count<T>::value >= 2 && !is_wrapper<T>::value) ||
804 (uncommon_type<T>::value && !is_direct_constructible<T, double>::value &&
805 !is_direct_constructible<T, int>::value) ||
806 (uncommon_type<T>::value && type_count<T>::value >= 2))>::type> {
807 static constexpr object_category value{object_category::tuple_value};
816template <
typename T>
struct classify_object<T, typename std::enable_if<is_mutable_container<T>::value>::type> {
817 static constexpr object_category value{object_category::container_value};
827 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> = detail::dummy>
828constexpr const char *type_name() {
833 enable_if_t<classify_object<T>::value == object_category::integral_value ||
834 classify_object<T>::value == object_category::integer_constructible,
835 detail::enabler> = detail::dummy>
836constexpr const char *type_name() {
841 enable_if_t<classify_object<T>::value == object_category::unsigned_integral, detail::enabler> = detail::dummy>
842constexpr const char *type_name() {
847 enable_if_t<classify_object<T>::value == object_category::floating_point ||
848 classify_object<T>::value == object_category::number_constructible ||
849 classify_object<T>::value == object_category::double_constructible,
850 detail::enabler> = detail::dummy>
851constexpr const char *type_name() {
857 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
858constexpr const char *type_name() {
864 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
865constexpr const char *type_name() {
871 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
872constexpr const char *type_name() {
878 enable_if_t<classify_object<T>::value >= object_category::string_assignable &&
879 classify_object<T>::value <= object_category::other,
880 detail::enabler> = detail::dummy>
881constexpr const char *type_name() {
886 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value >= 2,
887 detail::enabler> = detail::dummy>
888std::string type_name();
892 enable_if_t<classify_object<T>::value == object_category::container_value ||
893 classify_object<T>::value == object_category::wrapper_value,
894 detail::enabler> = detail::dummy>
895std::string type_name();
899 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value == 1,
900 detail::enabler> = detail::dummy>
901inline std::string type_name() {
902 return type_name<typename std::decay<typename std::tuple_element<0, T>::type>::type>();
906template <
typename T, std::
size_t I>
907inline typename std::enable_if<I == type_count_base<T>::value, std::string>::type tuple_name() {
908 return std::string{};
912template <
typename T, std::
size_t I>
913inline typename std::enable_if<(I < type_count_base<T>::value), std::string>::type tuple_name() {
914 auto str = std::string{type_name<typename std::decay<typename std::tuple_element<I, T>::type>::type>()} +
',' +
915 tuple_name<T, I + 1>();
916 if(str.back() ==
',')
923 enable_if_t<classify_object<T>::value == object_category::tuple_value && type_count_base<T>::value >= 2,
925inline std::string type_name() {
926 auto tname = std::string(1,
'[') + tuple_name<T, 0>();
927 tname.push_back(
']');
933 enable_if_t<classify_object<T>::value == object_category::container_value ||
934 classify_object<T>::value == object_category::wrapper_value,
936inline std::string type_name() {
937 return type_name<typename T::value_type>();
943template <typename T, enable_if_t<std::is_unsigned<T>::value, detail::enabler> = detail::dummy>
944bool integral_conversion(
const std::string &input, T &output)
noexcept {
945 if(input.empty() || input.front() ==
'-') {
950 std::uint64_t output_ll = std::strtoull(input.c_str(), &val, 0);
951 if(errno == ERANGE) {
954 output =
static_cast<T
>(output_ll);
955 if(val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll) {
959 std::int64_t output_sll = std::strtoll(input.c_str(), &val, 0);
960 if(val == (input.c_str() + input.size())) {
961 output = (output_sll < 0) ? static_cast<T>(0) : static_cast<T>(output_sll);
962 return (
static_cast<std::int64_t
>(output) == output_sll);
965 auto group_separators = get_group_separators();
966 if(input.find_first_of(group_separators) != std::string::npos) {
967 std::string nstring = input;
968 for(
auto &separator : group_separators) {
969 if(input.find_first_of(separator) != std::string::npos) {
970 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
973 return integral_conversion(nstring, output);
976 if(std::isspace(
static_cast<unsigned char>(input.back()))) {
977 return integral_conversion(trim_copy(input), output);
979 if(input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0) {
982 output_ll = std::strtoull(input.c_str() + 2, &val, 8);
983 if(errno == ERANGE) {
986 output =
static_cast<T
>(output_ll);
987 return (val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll);
989 if(input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0) {
995 output_ll = std::strtoull(input.c_str() + 2, &val, 2);
996 if(errno == ERANGE) {
999 output =
static_cast<T
>(output_ll);
1000 return (val == (input.c_str() + input.size()) &&
static_cast<std::uint64_t
>(output) == output_ll);
1007template <typename T, enable_if_t<std::is_signed<T>::value, detail::enabler> = detail::dummy>
1008bool integral_conversion(
const std::string &input, T &output)
noexcept {
1012 char *val =
nullptr;
1014 std::int64_t output_ll = std::strtoll(input.c_str(), &val, 0);
1015 if(errno == ERANGE) {
1018 output =
static_cast<T
>(output_ll);
1019 if(val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll) {
1022 if(input ==
"true") {
1024 output =
static_cast<T
>(1);
1028 auto group_separators = get_group_separators();
1029 if(input.find_first_of(group_separators) != std::string::npos) {
1030 for(
auto &separator : group_separators) {
1031 if(input.find_first_of(separator) != std::string::npos) {
1032 std::string nstring = input;
1033 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1034 return integral_conversion(nstring, output);
1038 if(std::isspace(
static_cast<unsigned char>(input.back()))) {
1039 return integral_conversion(trim_copy(input), output);
1041 if(input.compare(0, 2,
"0o") == 0 || input.compare(0, 2,
"0O") == 0) {
1044 output_ll = std::strtoll(input.c_str() + 2, &val, 8);
1045 if(errno == ERANGE) {
1048 output =
static_cast<T
>(output_ll);
1049 return (val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll);
1051 if(input.compare(0, 2,
"0b") == 0 || input.compare(0, 2,
"0B") == 0) {
1057 output_ll = std::strtoll(input.c_str() + 2, &val, 2);
1058 if(errno == ERANGE) {
1061 output =
static_cast<T
>(output_ll);
1062 return (val == (input.c_str() + input.size()) &&
static_cast<std::int64_t
>(output) == output_ll);
1069inline std::int64_t to_flag_value(std::string val)
noexcept {
1070 static const std::string trueString(
"true");
1071 static const std::string falseString(
"false");
1072 if(val == trueString) {
1075 if(val == falseString) {
1078 val = detail::to_lower(val);
1079 std::int64_t ret = 0;
1080 if(val.size() == 1) {
1081 if(val[0] >=
'1' && val[0] <=
'9') {
1082 return (
static_cast<std::int64_t
>(val[0]) -
'0');
1102 if(val == trueString || val ==
"on" || val ==
"yes" || val ==
"enable") {
1104 }
else if(val == falseString || val ==
"off" || val ==
"no" || val ==
"disable") {
1107 char *loc_ptr{
nullptr};
1108 ret = std::strtoll(val.c_str(), &loc_ptr, 0);
1109 if(loc_ptr != (val.c_str() + val.size()) && errno == 0) {
1117template <
typename T,
1118 enable_if_t<classify_object<T>::value == object_category::integral_value ||
1119 classify_object<T>::value == object_category::unsigned_integral,
1120 detail::enabler> = detail::dummy>
1121bool lexical_cast(
const std::string &input, T &output) {
1122 return integral_conversion(input, output);
1126template <
typename T,
1127 enable_if_t<classify_object<T>::value == object_category::char_value, detail::enabler> = detail::dummy>
1128bool lexical_cast(
const std::string &input, T &output) {
1129 if(input.size() == 1) {
1130 output =
static_cast<T
>(input[0]);
1133 return integral_conversion(input, output);
1137template <
typename T,
1138 enable_if_t<classify_object<T>::value == object_category::boolean_value, detail::enabler> = detail::dummy>
1139bool lexical_cast(
const std::string &input, T &output) {
1141 auto out = to_flag_value(input);
1144 }
else if(errno == ERANGE) {
1145 output = (input[0] !=
'-');
1153template <
typename T,
1154 enable_if_t<classify_object<T>::value == object_category::floating_point, detail::enabler> = detail::dummy>
1155bool lexical_cast(
const std::string &input, T &output) {
1159 char *val =
nullptr;
1160 auto output_ld = std::strtold(input.c_str(), &val);
1161 output =
static_cast<T
>(output_ld);
1162 if(val == (input.c_str() + input.size())) {
1165 while(std::isspace(
static_cast<unsigned char>(*val))) {
1167 if(val == (input.c_str() + input.size())) {
1173 auto group_separators = get_group_separators();
1174 if(input.find_first_of(group_separators) != std::string::npos) {
1175 for(
auto &separator : group_separators) {
1176 if(input.find_first_of(separator) != std::string::npos) {
1177 std::string nstring = input;
1178 nstring.erase(std::remove(nstring.begin(), nstring.end(), separator), nstring.end());
1179 return lexical_cast(nstring, output);
1187template <
typename T,
1188 enable_if_t<classify_object<T>::value == object_category::complex_number, detail::enabler> = detail::dummy>
1189bool lexical_cast(
const std::string &input, T &output) {
1190 using XC =
typename wrapped_type<T, double>::type;
1193 bool worked =
false;
1194 auto nloc = str1.find_last_of(
"+-");
1195 if(nloc != std::string::npos && nloc > 0) {
1196 worked = lexical_cast(str1.substr(0, nloc), x);
1197 str1 = str1.substr(nloc);
1198 if(str1.back() ==
'i' || str1.back() ==
'j')
1200 worked = worked && lexical_cast(str1, y);
1202 if(str1.back() ==
'i' || str1.back() ==
'j') {
1204 worked = lexical_cast(str1, y);
1207 worked = lexical_cast(str1, x);
1215 return from_stream(input, output);
1219template <
typename T,
1220 enable_if_t<classify_object<T>::value == object_category::string_assignable, detail::enabler> = detail::dummy>
1221bool lexical_cast(
const std::string &input, T &output) {
1229 enable_if_t<classify_object<T>::value == object_category::string_constructible, detail::enabler> = detail::dummy>
1230bool lexical_cast(
const std::string &input, T &output) {
1238 enable_if_t<classify_object<T>::value == object_category::wstring_assignable, detail::enabler> = detail::dummy>
1239bool lexical_cast(
const std::string &input, T &output) {
1240 output = widen(input);
1246 enable_if_t<classify_object<T>::value == object_category::wstring_constructible, detail::enabler> = detail::dummy>
1247bool lexical_cast(
const std::string &input, T &output) {
1248 output = T{widen(input)};
1253template <
typename T,
1254 enable_if_t<classify_object<T>::value == object_category::enumeration, detail::enabler> = detail::dummy>
1255bool lexical_cast(
const std::string &input, T &output) {
1256 typename std::underlying_type<T>::type val;
1257 if(!integral_conversion(input, val)) {
1260 output =
static_cast<T
>(val);
1265template <
typename T,
1266 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1267 std::is_assignable<T &, typename T::value_type>::value,
1268 detail::enabler> = detail::dummy>
1269bool lexical_cast(
const std::string &input, T &output) {
1270 typename T::value_type val;
1271 if(lexical_cast(input, val)) {
1275 return from_stream(input, output);
1278template <
typename T,
1279 enable_if_t<classify_object<T>::value == object_category::wrapper_value &&
1280 !std::is_assignable<T &, typename T::value_type>::value && std::is_assignable<T &, T>::value,
1281 detail::enabler> = detail::dummy>
1282bool lexical_cast(
const std::string &input, T &output) {
1283 typename T::value_type val;
1284 if(lexical_cast(input, val)) {
1288 return from_stream(input, output);
1294 enable_if_t<classify_object<T>::value == object_category::number_constructible, detail::enabler> = detail::dummy>
1295bool lexical_cast(
const std::string &input, T &output) {
1297 if(integral_conversion(input, val)) {
1303 if(lexical_cast(input, dval)) {
1308 return from_stream(input, output);
1314 enable_if_t<classify_object<T>::value == object_category::integer_constructible, detail::enabler> = detail::dummy>
1315bool lexical_cast(
const std::string &input, T &output) {
1317 if(integral_conversion(input, val)) {
1321 return from_stream(input, output);
1327 enable_if_t<classify_object<T>::value == object_category::double_constructible, detail::enabler> = detail::dummy>
1328bool lexical_cast(
const std::string &input, T &output) {
1330 if(lexical_cast(input, val)) {
1334 return from_stream(input, output);
1338template <
typename T,
1339 enable_if_t<classify_object<T>::value == object_category::other && std::is_assignable<T &, int>::value,
1340 detail::enabler> = detail::dummy>
1341bool lexical_cast(
const std::string &input, T &output) {
1343 if(integral_conversion(input, val)) {
1345#pragma warning(push)
1346#pragma warning(disable : 4800)
1359 return from_stream(input, output);
1364template <
typename T,
1365 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1366 is_istreamable<T>::value,
1367 detail::enabler> = detail::dummy>
1368bool lexical_cast(
const std::string &input, T &output) {
1369 return from_stream(input, output);
1374template <
typename T,
1375 enable_if_t<classify_object<T>::value == object_category::other && !std::is_assignable<T &, int>::value &&
1376 !is_istreamable<T>::value && !adl_detail::is_lexical_castable<T>::value,
1377 detail::enabler> = detail::dummy>
1378bool lexical_cast(
const std::string & , T & ) {
1379 static_assert(!std::is_same<T, T>::value,
1380 "option object type must have a lexical cast overload or streaming input operator(>>) defined, if it "
1381 "is convertible from another type use the add_option<T, XC>(...) with XC being the known type");
1387template <
typename AssignTo,
1389 enable_if_t<std::is_same<AssignTo, ConvertTo>::value &&
1390 (classify_object<AssignTo>::value == object_category::string_assignable ||
1391 classify_object<AssignTo>::value == object_category::string_constructible ||
1392 classify_object<AssignTo>::value == object_category::wstring_assignable ||
1393 classify_object<AssignTo>::value == object_category::wstring_constructible),
1394 detail::enabler> = detail::dummy>
1395bool lexical_assign(
const std::string &input, AssignTo &output) {
1396 return lexical_cast(input, output);
1400template <
typename AssignTo,
1402 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, AssignTo>::value &&
1403 classify_object<AssignTo>::value != object_category::string_assignable &&
1404 classify_object<AssignTo>::value != object_category::string_constructible &&
1405 classify_object<AssignTo>::value != object_category::wstring_assignable &&
1406 classify_object<AssignTo>::value != object_category::wstring_constructible,
1407 detail::enabler> = detail::dummy>
1408bool lexical_assign(
const std::string &input, AssignTo &output) {
1410 output = AssignTo{};
1414 return lexical_cast(input, output);
1418template <
typename AssignTo,
1420 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1421 classify_object<AssignTo>::value == object_category::wrapper_value,
1422 detail::enabler> = detail::dummy>
1423bool lexical_assign(
const std::string &input, AssignTo &output) {
1425 typename AssignTo::value_type emptyVal{};
1429 return lexical_cast(input, output);
1434template <
typename AssignTo,
1436 enable_if_t<std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, AssignTo>::value &&
1437 classify_object<AssignTo>::value != object_category::wrapper_value &&
1438 std::is_assignable<AssignTo &, int>::value,
1439 detail::enabler> = detail::dummy>
1440bool lexical_assign(
const std::string &input, AssignTo &output) {
1446 if(lexical_cast(input, val)) {
1447#if defined(__clang__)
1449#pragma clang diagnostic push
1450#pragma clang diagnostic ignored "-Wsign-conversion"
1453#if defined(__clang__)
1454#pragma clang diagnostic pop
1462template <
typename AssignTo,
1464 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && std::is_assignable<AssignTo &, ConvertTo &>::value,
1465 detail::enabler> = detail::dummy>
1466bool lexical_assign(
const std::string &input, AssignTo &output) {
1468 bool parse_result = (!input.empty()) ? lexical_cast(input, val) : true;
1472 return parse_result;
1479 enable_if_t<!std::is_same<AssignTo, ConvertTo>::value && !std::is_assignable<AssignTo &, ConvertTo &>::value &&
1480 std::is_move_assignable<AssignTo>::value,
1481 detail::enabler> = detail::dummy>
1482bool lexical_assign(
const std::string &input, AssignTo &output) {
1484 bool parse_result = input.empty() ? true : lexical_cast(input, val);
1486 output = AssignTo(val);
1488 return parse_result;
1492template <
typename AssignTo,
1494 enable_if_t<classify_object<ConvertTo>::value <= object_category::other &&
1495 classify_object<AssignTo>::value <= object_category::wrapper_value,
1496 detail::enabler> = detail::dummy>
1497bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1498 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1503template <
typename AssignTo,
1505 enable_if_t<(type_count<AssignTo>::value <= 2) && expected_count<AssignTo>::value == 1 &&
1506 is_tuple_like<ConvertTo>::value && type_count_base<ConvertTo>::value == 2,
1507 detail::enabler> = detail::dummy>
1508bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1510 using FirstType =
typename std::remove_const<typename std::tuple_element<0, ConvertTo>::type>::type;
1511 using SecondType =
typename std::tuple_element<1, ConvertTo>::type;
1514 bool retval = lexical_assign<FirstType, FirstType>(strings[0], v1);
1515 retval = retval && lexical_assign<SecondType, SecondType>((strings.size() > 1) ? strings[1] : std::string{}, v2);
1517 output = AssignTo{v1, v2};
1523template <
class AssignTo,
1525 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1526 type_count<ConvertTo>::value == 1,
1527 detail::enabler> = detail::dummy>
1528bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1529 output.erase(output.begin(), output.end());
1530 if(strings.empty()) {
1533 if(strings.size() == 1 && strings[0] ==
"{}") {
1536 bool skip_remaining =
false;
1537 if(strings.size() == 2 && strings[0] ==
"{}" && is_separator(strings[1])) {
1538 skip_remaining =
true;
1540 for(
const auto &elem : strings) {
1541 typename AssignTo::value_type out;
1542 bool retval = lexical_assign<typename AssignTo::value_type, typename ConvertTo::value_type>(elem, out);
1546 output.insert(output.end(), std::move(out));
1547 if(skip_remaining) {
1551 return (!output.empty());
1555template <class AssignTo, class ConvertTo, enable_if_t<is_complex<ConvertTo>::value, detail::enabler> = detail::dummy>
1556bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1558 if(strings.size() >= 2 && !strings[1].empty()) {
1559 using XC2 =
typename wrapped_type<ConvertTo, double>::type;
1561 auto str1 = strings[1];
1562 if(str1.back() ==
'i' || str1.back() ==
'j') {
1565 auto worked = lexical_cast(strings[0], x) && lexical_cast(str1, y);
1567 output = ConvertTo{x, y};
1571 return lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1575template <
class AssignTo,
1577 enable_if_t<is_mutable_container<AssignTo>::value && (expected_count<ConvertTo>::value == 1) &&
1578 (type_count<ConvertTo>::value == 1),
1579 detail::enabler> = detail::dummy>
1580bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1583 output.reserve(strings.size());
1584 for(
const auto &elem : strings) {
1586 output.emplace_back();
1587 retval = retval && lexical_assign<typename AssignTo::value_type, ConvertTo>(elem, output.back());
1589 return (!output.empty()) && retval;
1595template <
class AssignTo,
1597 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1598 type_count_base<ConvertTo>::value == 2,
1599 detail::enabler> = detail::dummy>
1600bool lexical_conversion(std::vector<std::string> strings, AssignTo &output);
1603template <
class AssignTo,
1605 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1606 type_count_base<ConvertTo>::value != 2 &&
1607 ((type_count<ConvertTo>::value > 2) ||
1608 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1609 detail::enabler> = detail::dummy>
1610bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1613template <
class AssignTo,
1615 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1616 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1617 type_count<ConvertTo>::value > 2),
1618 detail::enabler> = detail::dummy>
1619bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output);
1623template <
typename AssignTo,
1625 enable_if_t<!is_tuple_like<AssignTo>::value && !is_mutable_container<AssignTo>::value &&
1626 classify_object<ConvertTo>::value != object_category::wrapper_value &&
1627 (is_mutable_container<ConvertTo>::value || type_count<ConvertTo>::value > 2),
1628 detail::enabler> = detail::dummy>
1629bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1631 if(strings.size() > 1 || (!strings.empty() && !(strings.front().empty()))) {
1633 auto retval = lexical_conversion<ConvertTo, ConvertTo>(strings, val);
1634 output = AssignTo{val};
1637 output = AssignTo{};
1642template <
class AssignTo,
class ConvertTo, std::
size_t I>
1643inline typename std::enable_if<(I >= type_count_base<AssignTo>::value),
bool>::type
1644tuple_conversion(
const std::vector<std::string> &, AssignTo &) {
1649template <
class AssignTo,
class ConvertTo>
1650inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && type_count<ConvertTo>::value == 1,
bool>::type
1651tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1652 auto retval = lexical_assign<AssignTo, ConvertTo>(strings[0], output);
1653 strings.erase(strings.begin());
1658template <
class AssignTo,
class ConvertTo>
1659inline typename std::enable_if<!is_mutable_container<ConvertTo>::value && (type_count<ConvertTo>::value > 1) &&
1660 type_count<ConvertTo>::value == type_count_min<ConvertTo>::value,
1662tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1663 auto retval = lexical_conversion<AssignTo, ConvertTo>(strings, output);
1664 strings.erase(strings.begin(), strings.begin() + type_count<ConvertTo>::value);
1669template <
class AssignTo,
class ConvertTo>
1670inline typename std::enable_if<is_mutable_container<ConvertTo>::value ||
1671 type_count<ConvertTo>::value != type_count_min<ConvertTo>::value,
1673tuple_type_conversion(std::vector<std::string> &strings, AssignTo &output) {
1675 std::size_t index{subtype_count_min<ConvertTo>::value};
1676 const std::size_t mx_count{subtype_count<ConvertTo>::value};
1677 const std::size_t mx{(std::min)(mx_count, strings.size() - 1)};
1680 if(is_separator(strings[index])) {
1685 bool retval = lexical_conversion<AssignTo, ConvertTo>(
1686 std::vector<std::string>(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index)), output);
1687 if(strings.size() > index) {
1688 strings.erase(strings.begin(), strings.begin() +
static_cast<std::ptrdiff_t
>(index) + 1);
1696template <
class AssignTo,
class ConvertTo, std::
size_t I>
1697inline typename std::enable_if<(I < type_count_base<AssignTo>::value),
bool>::type
1698tuple_conversion(std::vector<std::string> strings, AssignTo &output) {
1700 using ConvertToElement =
typename std::
1701 conditional<is_tuple_like<ConvertTo>::value,
typename std::tuple_element<I, ConvertTo>::type, ConvertTo>::type;
1702 if(!strings.empty()) {
1703 retval = retval && tuple_type_conversion<typename std::tuple_element<I, AssignTo>::type, ConvertToElement>(
1704 strings, std::get<I>(output));
1706 retval = retval && tuple_conversion<AssignTo, ConvertTo, I + 1>(std::move(strings), output);
1711template <
class AssignTo,
1713 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1714 type_count_base<ConvertTo>::value == 2,
1716bool lexical_conversion(std::vector<std::string> strings, AssignTo &output) {
1718 while(!strings.empty()) {
1720 typename std::remove_const<typename std::tuple_element<0, typename ConvertTo::value_type>::type>::type v1;
1721 typename std::tuple_element<1, typename ConvertTo::value_type>::type v2;
1722 bool retval = tuple_type_conversion<decltype(v1), decltype(v1)>(strings, v1);
1723 if(!strings.empty()) {
1724 retval = retval && tuple_type_conversion<decltype(v2), decltype(v2)>(strings, v2);
1727 output.insert(output.end(),
typename AssignTo::value_type{v1, v2});
1732 return (!output.empty());
1736template <
class AssignTo,
1738 enable_if_t<is_tuple_like<AssignTo>::value && is_tuple_like<ConvertTo>::value &&
1739 (type_count_base<ConvertTo>::value != type_count<ConvertTo>::value ||
1740 type_count<ConvertTo>::value > 2),
1742bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1744 !is_tuple_like<ConvertTo>::value || type_count_base<AssignTo>::value == type_count_base<ConvertTo>::value,
1745 "if the conversion type is defined as a tuple it must be the same size as the type you are converting to");
1746 return tuple_conversion<AssignTo, ConvertTo, 0>(strings, output);
1750template <
class AssignTo,
1752 enable_if_t<is_mutable_container<AssignTo>::value && is_mutable_container<ConvertTo>::value &&
1753 type_count_base<ConvertTo>::value != 2 &&
1754 ((type_count<ConvertTo>::value > 2) ||
1755 (type_count<ConvertTo>::value > type_count_base<ConvertTo>::value)),
1757bool lexical_conversion(
const std::vector<std ::string> &strings, AssignTo &output) {
1760 std::vector<std::string> temp;
1762 std::size_t icount{0};
1763 std::size_t xcm{type_count<ConvertTo>::value};
1764 auto ii_max = strings.size();
1765 while(ii < ii_max) {
1766 temp.push_back(strings[ii]);
1769 if(icount == xcm || is_separator(temp.back()) || ii == ii_max) {
1770 if(
static_cast<int>(xcm) > type_count_min<ConvertTo>::value && is_separator(temp.back())) {
1773 typename AssignTo::value_type temp_out;
1775 lexical_conversion<typename AssignTo::value_type, typename ConvertTo::value_type>(temp, temp_out);
1780 output.insert(output.end(), std::move(temp_out));
1788template <
typename AssignTo,
1790 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1791 std::is_assignable<ConvertTo &, ConvertTo>::value,
1792 detail::enabler> = detail::dummy>
1793bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1794 if(strings.empty() || strings.front().empty()) {
1795 output = ConvertTo{};
1798 typename ConvertTo::value_type val;
1799 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1800 output = ConvertTo{val};
1807template <
typename AssignTo,
1809 enable_if_t<classify_object<ConvertTo>::value == object_category::wrapper_value &&
1810 !std::is_assignable<AssignTo &, ConvertTo>::value,
1811 detail::enabler> = detail::dummy>
1812bool lexical_conversion(
const std::vector<std::string> &strings, AssignTo &output) {
1813 using ConvertType =
typename ConvertTo::value_type;
1814 if(strings.empty() || strings.front().empty()) {
1815 output = ConvertType{};
1819 if(lexical_conversion<typename ConvertTo::value_type, typename ConvertTo::value_type>(strings, val)) {
1827inline std::string sum_string_vector(
const std::vector<std::string> &values) {
1831 for(
const auto &arg : values) {
1833 auto comp = lexical_cast(arg, tv);
1836 auto fv = detail::to_flag_value(arg);
1837 fail = (errno != 0);
1841 tv =
static_cast<double>(fv);
1846 for(
const auto &arg : values) {
1850 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