소스 검색

Pull matcher definitions out into their own headers.

Sam Jaffe 6 년 전
부모
커밋
c4f1d4b721
5개의 변경된 파일70개의 추가작업 그리고 60개의 파일을 삭제
  1. 5 60
      include/match/match.hpp
  2. 9 0
      include/match/matchers/any.hpp
  3. 18 0
      include/match/matchers/any_in.hpp
  4. 20 0
      include/match/matchers/any_of.hpp
  5. 18 0
      include/match/matchers/matches.hpp

+ 5 - 60
include/match/match.hpp

@@ -7,68 +7,8 @@
 
 #pragma once
 
-#include <array>
 #include <tuple>
 
-namespace matcher {
-  struct {} any;
-  using any_t = decltype(any);
-  
-  template <typename T>
-  bool operator==(T const &, any_t) { return true; }
-}
-
-namespace matcher {
-  template <typename T, size_t I>
-  struct any_of_t {
-    std::array<T, I> options;
-  };
-  
-  template <typename T, size_t I>
-  bool operator==(T const & t, any_of_t<T, I> const & of) {
-    return std::find(of.options.begin(), of.options.end(), t) != of.options.end();
-  }
-  
-  template <typename... Args>
-  any_of_t<typename std::common_type<Args...>::type, sizeof...(Args)> any_of(Args &&... args) {
-    return {{args...}};
-  }
-}
-
-namespace matcher {
-  template <typename Container>
-  struct any_in_t {
-    Container options;
-  };
-  
-  template <typename T, typename Container>
-  bool operator==(T const & t, any_in_t<Container> const & of) {
-    return std::find(of.options.begin(), of.options.end(), t) != of.options.end();
-  }
-  
-  template <typename Container>
-  any_in_t<Container> any_in(Container && args) {
-    return {args};
-  }
-}
-
-namespace matcher {
-  template <typename Pred>
-  struct predicate_t {
-    Pred predicate;
-  };
-  
-  template <typename T, typename Pred>
-  bool operator==(T const & t, predicate_t<Pred> const & of) {
-    return of.predicate(t);
-  }
-  
-  template <typename Pred>
-  predicate_t<Pred> matches(Pred && args) {
-    return {args};
-  }
-}
-
 namespace matcher {
   template <typename... Args>
   struct matcher {
@@ -111,3 +51,8 @@ namespace matcher {
 
 #define nomatch( ) \
   if ( _matcher_local.unmatched( ) )
+
+#include "matchers/any_in.hpp"
+#include "matchers/any_of.hpp"
+#include "matchers/any.hpp"
+#include "matchers/matches.hpp"

+ 9 - 0
include/match/matchers/any.hpp

@@ -0,0 +1,9 @@
+#pragma once
+
+namespace matcher {
+  struct {} any;
+  using any_t = decltype(any);
+  
+  template <typename T>
+  bool operator==(T const &, any_t) { return true; }
+}

+ 18 - 0
include/match/matchers/any_in.hpp

@@ -0,0 +1,18 @@
+#pragma once
+
+namespace matcher {
+  template <typename Container>
+  struct any_in_t {
+    Container options;
+  };
+  
+  template <typename T, typename Container>
+  bool operator==(T const & t, any_in_t<Container> const & of) {
+    return std::find(of.options.begin(), of.options.end(), t) != of.options.end();
+  }
+  
+  template <typename Container>
+  any_in_t<Container> any_in(Container && args) {
+    return {args};
+  }
+}

+ 20 - 0
include/match/matchers/any_of.hpp

@@ -0,0 +1,20 @@
+#pragma once
+
+#include <array>
+
+namespace matcher {
+  template <typename T, size_t I>
+  struct any_of_t {
+    std::array<T, I> options;
+  };
+  
+  template <typename T, size_t I>
+  bool operator==(T const & t, any_of_t<T, I> const & of) {
+    return std::find(of.options.begin(), of.options.end(), t) != of.options.end();
+  }
+  
+  template <typename... Args>
+  any_of_t<typename std::common_type<Args...>::type, sizeof...(Args)> any_of(Args &&... args) {
+    return {{args...}};
+  }
+}

+ 18 - 0
include/match/matchers/matches.hpp

@@ -0,0 +1,18 @@
+#pragma once
+
+namespace matcher {
+  template <typename Pred>
+  struct predicate_t {
+    Pred predicate;
+  };
+  
+  template <typename T, typename Pred>
+  bool operator==(T const & t, predicate_t<Pred> const & of) {
+    return of.predicate(t);
+  }
+  
+  template <typename Pred>
+  predicate_t<Pred> matches(Pred && args) {
+    return {args};
+  }
+}