Browse Source

Fixing reference type BS

Sam Jaffe 5 years ago
parent
commit
8b6ca50450
2 changed files with 8 additions and 2 deletions
  1. 7 1
      include/cli/cli.h
  2. 1 1
      include/cli/message.h

+ 7 - 1
include/cli/cli.h

@@ -40,13 +40,19 @@ public:
   }
   void run() const;
   template <typename T> static T from_string(std::string const &);
+  template <typename T, size_t I>
+  static auto from_string(std::string const & value) {
+    using E = std::tuple_element_t<I, T>;
+    using V = std::remove_cv_t<std::remove_reference_t<E>>;
+    return from_string<V>(value);
+  }
 };
 
 template <typename... Args, size_t... Is>
 void cli_invoke(std::function<void(Args...)> cb, cli::args_t const & args,
                 std::index_sequence<Is...>) {
   using tuple = std::tuple<Args...>;
-  cb(cli::from_string<std::tuple_element_t<Is, tuple>>(args[Is])...);
+  cb(cli::from_string<tuple, Is>(args[Is])...);
 }
 
 template <typename... Args>

+ 1 - 1
include/cli/message.h

@@ -21,7 +21,7 @@ void print(std::ostream &os, T const & tup, std::index_sequence<Is...>) {
   os << std::noboolalpha;
 }
 
-template <typename T> struct up_string { using type = T; };
+template <typename T> struct up_string { using type = std::remove_reference_t<T>; };
 template <size_t N> struct up_string<char const(&)[N]> {
   using type = std::string;
 };