Browse Source

refactor: apply clang-format to requries clauses

Sam Jaffe 3 tháng trước cách đây
mục cha
commit
cb04f35da2

+ 10 - 8
include/jvalidate/detail/out.h

@@ -9,7 +9,8 @@ constexpr struct discard_out_t {
 } discard_out;
 
 template <typename T>
-requires(std::is_same_v<T, std::decay_t<T>>) class out {
+  requires(std::is_same_v<T, std::decay_t<T>>)
+class out {
 private:
   T * ref_ = nullptr;
 
@@ -21,7 +22,7 @@ public:
   explicit operator bool() const { return ref_; }
 
   template <typename U>
-  requires std::is_constructible_v<T, U>
+    requires std::is_constructible_v<T, U>
   void operator=(U && val) {
     if (ref_) {
       *ref_ = std::forward<U>(val);
@@ -31,7 +32,8 @@ public:
 };
 
 template <typename T>
-requires(std::is_same_v<T, std::decay_t<T>>) class inout {
+  requires(std::is_same_v<T, std::decay_t<T>>)
+class inout {
 private:
   std::variant<T, T *> ref_;
 
@@ -48,14 +50,14 @@ public:
   }
 
   template <typename U>
-  requires std::is_constructible_v<T, U> T const & operator=(U && val) {
+    requires std::is_constructible_v<T, U>
+  T const & operator=(U && val) {
     struct {
       U && val;
-      void operator()(T & in) const { in = std::forward<U>(val); }
-      void operator()(T * in) const { *in = std::forward<U>(val); }
+      T const & operator()(T & in) const { return in = std::forward<U>(val); }
+      T const & operator()(T * in) const { return *in = std::forward<U>(val); }
     } visitor{std::forward<U>(val)};
-    std::visit(visitor, ref_);
-    return static_cast<T const &>(*this);
+    return std::visit(visitor, ref_);
   }
 };
 }

+ 12 - 12
include/jvalidate/forward.h

@@ -75,17 +75,17 @@ class Node;
 
 namespace jvalidate {
 template <typename It>
-concept ArrayIterator = std::forward_iterator<It> and std::is_default_constructible_v<It> and
-    requires(It const it) {
-  { *it } -> std::convertible_to<adapter::Adapter const &>;
-};
+concept ArrayIterator =
+    std::forward_iterator<It> and std::is_default_constructible_v<It> and requires(It const it) {
+      { *it } -> std::convertible_to<adapter::Adapter const &>;
+    };
 
 template <typename It>
-concept ObjectIterator = std::forward_iterator<It> and std::is_default_constructible_v<It> and
-    requires(It const it) {
-  { it->first } -> std::convertible_to<std::string_view>;
-  { it->second } -> std::convertible_to<adapter::Adapter const &>;
-};
+concept ObjectIterator =
+    std::forward_iterator<It> and std::is_default_constructible_v<It> and requires(It const it) {
+      { it->first } -> std::convertible_to<std::string_view>;
+      { it->second } -> std::convertible_to<adapter::Adapter const &>;
+    };
 
 template <typename A>
 concept ArrayAdapter = requires(A const a) {
@@ -121,13 +121,13 @@ concept Adapter = std::is_base_of_v<adapter::Adapter, A> && requires(A const a)
 
 template <typename A>
 concept MutableObject = ObjectAdapter<A> && requires(A const a) {
-  {a.assign("", std::declval<adapter::Const>())};
+  { a.assign("", std::declval<adapter::Const>()) };
 };
 
 template <typename A>
 concept MutableAdapter = Adapter<A> && requires(A const a) {
-  {a.assign(std::declval<adapter::Const>())};
-  {a.assign(std::declval<adapter::Adapter>())};
+  { a.assign(std::declval<adapter::Const>()) };
+  { a.assign(std::declval<adapter::Adapter>()) };
   { a.as_object() } -> MutableObject;
 };
 

+ 2 - 1
include/jvalidate/validation_visitor.h

@@ -598,7 +598,8 @@ public:
 
 private:
   template <typename S>
-  requires(std::is_constructible_v<std::string, S>) static std::string fmt(S const & str) {
+    requires(std::is_constructible_v<std::string, S>)
+  static std::string fmt(S const & str) {
     return str;
   }
 

+ 4 - 3
include/jvalidate/validator.h

@@ -31,8 +31,8 @@ public:
       : schema_(schema), cfg_(cfg) {}
 
   template <Adapter A>
-  requires(not MutableAdapter<A>) bool validate(A const & json,
-                                                ValidationResult * result = nullptr) {
+    requires(not MutableAdapter<A>)
+  bool validate(A const & json, ValidationResult * result = nullptr) {
     EXPECT_M(not cfg_.construct_default_values,
              "Cannot perform mutations on an immutable JSON Adapter");
     return static_cast<bool>(
@@ -45,7 +45,8 @@ public:
   }
 
   template <typename JSON>
-  requires(not Adapter<JSON>) bool validate(JSON & json, ValidationResult * result = nullptr) {
+    requires(not Adapter<JSON>)
+  bool validate(JSON & json, ValidationResult * result = nullptr) {
     return validate(adapter::AdapterFor<JSON>(json), result);
   }
 };