@@ -605,11 +605,10 @@ class Argument {
605
605
if constexpr (!details::IsContainer<T>) {
606
606
return get<T>() == rhs;
607
607
} else {
608
- using ValueType = typename T::value_type;
609
608
auto lhs = get<T>();
610
609
return std::equal (std::begin (lhs), std::end (lhs), std::begin (rhs),
611
610
std::end (rhs), [](const auto &lhs, const auto &rhs) {
612
- return std::any_cast< const ValueType &>( lhs) == rhs;
611
+ return lhs == rhs;
613
612
});
614
613
}
615
614
}
@@ -856,16 +855,16 @@ class Argument {
856
855
* Get argument value given a type
857
856
* @throws std::logic_error in case of incompatible types
858
857
*/
859
- template <typename T> T get () const {
858
+ template <typename T> auto get () const -> std::conditional_t<details::IsContainer<T>, T, const T&> {
860
859
if (!m_values.empty ()) {
861
860
if constexpr (details::IsContainer<T>) {
862
861
return any_cast_container<T>(m_values);
863
862
} else {
864
- return std::any_cast<T>(m_values.front ());
863
+ return * std::any_cast<T>(& m_values.front ());
865
864
}
866
865
}
867
866
if (m_default_value.has_value ()) {
868
- return std::any_cast<T>(m_default_value);
867
+ return * std::any_cast<T>(& m_default_value);
869
868
}
870
869
if constexpr (details::IsContainer<T>) {
871
870
if (!m_accepts_optional_like_value) {
@@ -901,7 +900,7 @@ class Argument {
901
900
T result;
902
901
std::transform (
903
902
std::begin (operand), std::end (operand), std::back_inserter (result),
904
- [](const auto &value) { return std::any_cast<ValueType>(value); });
903
+ [](const auto &value) { return * std::any_cast<ValueType>(& value); });
905
904
return result;
906
905
}
907
906
@@ -1057,7 +1056,8 @@ class ArgumentParser {
1057
1056
* @throws std::logic_error if the option has no value
1058
1057
* @throws std::bad_any_cast if the option is not of type T
1059
1058
*/
1060
- template <typename T = std::string> T get (std::string_view arg_name) const {
1059
+ template <typename T = std::string> auto get (std::string_view arg_name) const
1060
+ -> std::conditional_t<details::IsContainer<T>, T, const T&> {
1061
1061
if (!m_is_parsed) {
1062
1062
throw std::logic_error (" Nothing parsed, no arguments are available." );
1063
1063
}
0 commit comments