瀏覽代碼

feat: add automatic binding for string-likes such as fs::path

Sam Jaffe 3 年之前
父節點
當前提交
0bb49831e5
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      include/string_utils/cast.h

+ 8 - 0
include/string_utils/cast.h

@@ -114,6 +114,14 @@ template <typename T> struct cast_helper<T, std::enable_if_t<detail::is_tuple<T>
   }
 };
 
+template <typename T>
+struct cast_helper<T, std::enable_if_t<std::is_constructible_v<T, std::string_view>>> {
+  bool operator()(std::string_view str, T & to) const noexcept {
+    to = str;
+    return true;
+  }
+};
+
 template <typename... Ts>
 struct cast_helper<std::variant<Ts...>> {
   bool operator()(std::string_view str, std::variant<Ts...> & to) const noexcept {