Преглед изворни кода

fix: allow vector<string> being passed into cast(Out&, vector)

Sam Jaffe пре 2 година
родитељ
комит
545cac4005
2 измењених фајлова са 8 додато и 1 уклоњено
  1. 6 1
      include/string_utils/cast.h
  2. 2 0
      include/string_utils/forwards.h

+ 6 - 1
include/string_utils/cast.h

@@ -137,6 +137,11 @@ bool cast(Out & out, std::vector<std::string_view> const & strs) noexcept {
   }
 }
 
+template <typename Out, typename S>
+bool cast(Out & out, std::vector<S> const & strs) noexcept {
+  return cast(out, std::vector<std::string_view>(strs.begin(), strs.end()));
+}
+
 template <typename T> std::pair<T, bool> cast(std::string_view str) noexcept {
   std::pair<detail::decay_t<T>, bool> rval;
   using ::string_utils::cast;
@@ -146,7 +151,7 @@ template <typename T> std::pair<T, bool> cast(std::string_view str) noexcept {
 
 template <typename T, typename S>
 std::pair<T, bool> cast(std::vector<S> const & strs) noexcept {
-  std::vector<std::string_view> tmp{strs.begin(), strs.end()};
+  std::vector<std::string_view> tmp(strs.begin(), strs.end());
   std::pair<detail::decay_t<T>, bool> rval;
   using ::string_utils::cast;
   rval.second = cast(rval.first, tmp);

+ 2 - 0
include/string_utils/forwards.h

@@ -24,4 +24,6 @@ template <typename Out> bool cast(Out & out, std::string_view str) noexcept;
 
 template <typename Out>
 bool cast(Out & out, std::vector<std::string_view> const & strs) noexcept;
+template <typename Out, typename S>
+bool cast(Out & out, std::vector<S> const & str) noexcept;
 }