Browse Source

fix: compiler/merge errors

Sam Jaffe 1 năm trước cách đây
mục cha
commit
e45b1893e5

+ 6 - 3
include/jvalidate/detail/scoped_state.h

@@ -1,10 +1,12 @@
 #pragma once
 
 #include <functional>
+#include <type_traits>
 
 #define CONCAT2(A, B) A##B
 #define CONCAT(A, B) CONCAT2(A, B)
-#define scoped_state(prop, value) auto CONCAT(scoped_state_, __LINE__) = ScopedState(prop, value)
+#define scoped_state(prop, value)                                                                  \
+  auto CONCAT(scoped_state_, __LINE__) = detail::ScopedState(prop, value)
 
 namespace jvalidate::detail {
 class ScopedState {
@@ -12,8 +14,9 @@ private:
   std::function<void()> reset_;
 
 public:
-  template <typename T>
-  ScopedState(T & prop, T value) : reset_([reset = prop, &prop]() { prop = reset; }) {
+  template <typename T, typename S>
+  requires(std::is_constructible_v<T, S>) ScopedState(T & prop, S value)
+      : reset_([reset = prop, &prop]() { prop = reset; }) {
     prop = std::move(value);
   }
 

+ 7 - 8
include/jvalidate/validation_visitor.h

@@ -114,21 +114,20 @@ public:
   }
 
   Status visit(constraint::AnyOfConstraint const & cons) const {
-    Status rval = Status::Reject;
-
+    std::optional<size_t> first_validated;
     for (auto const & [index, subschema] : detail::enumerate(cons.children)) {
       if (validate_subschema(subschema, index)) {
-        rval = Status::Accept;
+        first_validated = index;
       }
-      if (not visited_ && rval == Status::Accept) {
+      if (not visited_ && first_validated.has_value()) {
         break;
       }
     }
 
-    if (rval == Status::Reject) {
-      return note(rval, "validates none of the subschemas");
+    if (first_validated.has_value()) {
+      return note(Status::Accept, "validates subschema ", *first_validated);
     }
-    return note(rval, "validates subschema ", i);
+    return note(Status::Reject, "validates none of the subschemas");
   }
 
   Status visit(constraint::OneOfConstraint const & cons) const {
@@ -162,7 +161,7 @@ public:
     bool const if_true = [this, &cons]() {
       scoped_state(tracking_, StoreResults::ForAnything);
       return validate_subschema(cons.if_constraint);
-    };
+    }();
     if (if_true) {
       return validate_subschema(cons.then_constraint, detail::parent, "then");
     }