From bbbf0ba2e57ae202aa83cd2c8178f772a2e14a78 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Fri, 18 Aug 2023 19:22:12 -0400 Subject: [PATCH] fix lvalue reference issue with stoi, get_cast now exists --- include/blt/parse/argparse.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/include/blt/parse/argparse.h b/include/blt/parse/argparse.h index aad19fc..7a6d453 100755 --- a/include/blt/parse/argparse.h +++ b/include/blt/parse/argparse.h @@ -330,6 +330,16 @@ namespace blt return std::holds_alternative(v) && std::holds_alternative(std::get(v)); } + + template + static inline T& get(arg_data_t& v) + { + if constexpr (std::is_same_v) + return std::get(v); + else + return std::get(std::get(v)); + } + /** * Attempt to cast the variant stored in the arg results to the requested type * if user is requesting an int, but holds a string, we are going to make the assumption the data can be converted @@ -339,7 +349,7 @@ namespace blt * @return */ template - static inline T& get(arg_data_t& v) + static inline T get_cast(arg_data_t& v) { if constexpr (std::is_same_v) return std::get(v); @@ -348,8 +358,11 @@ namespace blt auto t = std::get(v); // user is requesting an int, but holds a string, we are going to make the assumption the data can be converted // it is up to the user to deal with the variant if they do not want this behaviour! - if constexpr (std::holds_alternative(t) && std::is_same_v) - return std::stoi(std::get(t)); + if constexpr (std::is_same_v) + { + if (std::holds_alternative(t)) + return std::stoi(std::get(t)); + } return std::get(t); } }