Browse Source

refactor: move compatibility headers into compat directory

Sam Jaffe 3 months ago
parent
commit
09060ae9bd

+ 0 - 4
include/jvalidate/adapter.h

@@ -1,11 +1,7 @@
 #pragma once
 
-#include <cmath>
 #include <cstdint>
-#include <limits>
-#include <map>
 #include <optional>
-#include <string_view>
 
 #include <jvalidate/detail/array_iterator.h>
 #include <jvalidate/detail/number.h>

+ 4 - 1
include/jvalidate/detail/compare.h

@@ -2,8 +2,10 @@
 
 #include <compare>
 
+// Apple Clang does not properly support <=> in the STL - so we need to force it
+#if __cpp_lib_three_way_comparison < 201907L
 namespace std {
-template <typename T> std::strong_ordering operator<=>(T const & lhs, T const & rhs) {
+template <typename T> auto operator<=>(T const & lhs, T const & rhs) {
   if (lhs < rhs) {
     return std::strong_ordering::less;
   }
@@ -13,3 +15,4 @@ template <typename T> std::strong_ordering operator<=>(T const & lhs, T const &
   return std::strong_ordering::equal;
 }
 }
+#endif

+ 8 - 1
include/jvalidate/detail/enumerate.h

@@ -20,6 +20,13 @@ using std::ranges::views::enumerate;
 
 namespace jvalidate::detail {
 
+/**
+ * @brief A replacement for std::ranges::views::enumerate in C++20 (as enumerate
+ * is a C++23 feature).
+ * Much like python's enumerate() function, this is an iterator adapter that
+ * attaches the "index" of the iteration to each element - incrementing it as
+ * we go.
+ */
 template <typename It> class enumurate_iterator {
 public:
   using traits_t = std::iterator_traits<It>;
@@ -28,7 +35,7 @@ public:
   using reference = std::pair<size_t const &, typename traits_t::reference>;
   using pointer = DerefProxy<reference>;
   using difference_type = typename traits_t::difference_type;
-  using iterator_category = typename traits_t::iterator_category;
+  using iterator_category = std::forward_iterator_tag;
 
 private:
   size_t index_ = 0;

+ 1 - 1
include/jvalidate/constraint.h

@@ -14,7 +14,7 @@
 #include <jvalidate/constraint/object_constraint.h>
 #include <jvalidate/constraint/string_constraint.h>
 
-#include <jvalidate/detail/enumerate.h>
+#include <jvalidate/compat/enumerate.h>
 #include <jvalidate/detail/expect.h>
 #include <jvalidate/detail/parser_context.h>
 #include <jvalidate/detail/vocabulary.h>

+ 1 - 1
include/jvalidate/detail/anchor.h

@@ -6,7 +6,7 @@
 #include <string>
 #include <string_view>
 
-#include <jvalidate/detail/compare.h>
+#include <jvalidate/compat/compare.h>
 #include <jvalidate/detail/expect.h>
 
 namespace jvalidate::detail {

+ 1 - 1
include/jvalidate/detail/pointer.h

@@ -9,7 +9,7 @@
 #include <variant>
 #include <vector>
 
-#include <jvalidate/detail/compare.h>
+#include <jvalidate/compat/compare.h>
 #include <jvalidate/forward.h>
 
 namespace jvalidate::detail {

+ 1 - 0
include/jvalidate/detail/reference_manager.h

@@ -6,6 +6,7 @@
 #include <unordered_map>
 #include <unordered_set>
 
+#include <jvalidate/compat/enumerate.h>
 #include <jvalidate/detail/anchor.h>
 #include <jvalidate/detail/dynamic_reference_context.h>
 #include <jvalidate/detail/expect.h>

+ 1 - 1
include/jvalidate/uri.h

@@ -3,7 +3,7 @@
 #include <string>
 #include <string_view>
 
-#include <jvalidate/detail/compare.h>
+#include <jvalidate/compat/compare.h>
 #include <jvalidate/detail/expect.h>
 
 namespace jvalidate {

+ 1 - 1
include/jvalidate/validation_visitor.h

@@ -5,13 +5,13 @@
 #include <unordered_map>
 #include <vector>
 
+#include <jvalidate/compat/enumerate.h>
 #include <jvalidate/constraint/array_constraint.h>
 #include <jvalidate/constraint/general_constraint.h>
 #include <jvalidate/constraint/number_constraint.h>
 #include <jvalidate/constraint/object_constraint.h>
 #include <jvalidate/constraint/string_constraint.h>
 #include <jvalidate/constraint/visitor.h>
-#include <jvalidate/detail/enumerate.h>
 #include <jvalidate/detail/expect.h>
 #include <jvalidate/detail/iostream.h>
 #include <jvalidate/detail/number.h>