Kaynağa Gözat

view: join -> operator|

Michele Caini 1 yıl önce
ebeveyn
işleme
47d0a4328f
2 değiştirilmiş dosya ile 9 ekleme ve 10 silme
  1. 6 8
      src/entt/entity/view.hpp
  2. 3 2
      test/entt/entity/view.cpp

+ 6 - 8
src/entt/entity/view.hpp

@@ -644,13 +644,12 @@ public:
 
 
     /**
     /**
      * @brief Combines a view and a storage in _more specific_ view.
      * @brief Combines a view and a storage in _more specific_ view.
-     * @tparam OGet Type of storage to join the view with.
-     * @param other The storage for the type to join the view with.
+     * @tparam OGet Type of storage to combine the view with.
+     * @param other The storage for the type to combine the view with.
      * @return A more specific view.
      * @return A more specific view.
      */
      */
     template<typename OGet>
     template<typename OGet>
-    [[nodiscard]] auto join(OGet &other) const noexcept {
-        static_assert(std::is_base_of_v<common_type, OGet>, "Unexpected storage type");
+    [[nodiscard]] std::enable_if_t<std::is_base_of_v<common_type, OGet>, basic_view<get_t<Get..., OGet>, exclude_t<Exclude...>>> operator|(OGet &other) const noexcept {
         return *this | basic_view<get_t<OGet>, exclude_t<>>{other};
         return *this | basic_view<get_t<OGet>, exclude_t<>>{other};
     }
     }
 
 
@@ -1086,13 +1085,12 @@ public:
 
 
     /**
     /**
      * @brief Combines a view and a storage in _more specific_ view.
      * @brief Combines a view and a storage in _more specific_ view.
-     * @tparam OGet Type of storage to join the view with.
-     * @param other The storage for the type to join the view with.
+     * @tparam OGet Type of storage to combine the view with.
+     * @param other The storage for the type to combine the view with.
      * @return A more specific view.
      * @return A more specific view.
      */
      */
     template<typename OGet>
     template<typename OGet>
-    [[nodiscard]] auto join(OGet &other) const noexcept {
-        static_assert(std::is_base_of_v<common_type, OGet>, "Unexpected storage type");
+    [[nodiscard]] std::enable_if_t<std::is_base_of_v<common_type, OGet>, basic_view<get_t<Get, OGet>, exclude_t<>>> operator|(OGet &other) const noexcept {
         return *this | basic_view<get_t<OGet>, exclude_t<>>{other};
         return *this | basic_view<get_t<OGet>, exclude_t<>>{other};
     }
     }
 
 

+ 3 - 2
test/entt/entity/view.cpp

@@ -1541,8 +1541,9 @@ TEST(View, Pipe) {
     entt::basic_view view3{std::get<2>(storage)};
     entt::basic_view view3{std::get<2>(storage)};
     entt::basic_view view4{std::as_const(std::get<3>(storage))};
     entt::basic_view view4{std::as_const(std::get<3>(storage))};
 
 
-    testing::StaticAssertTypeEq<decltype(view1.join(std::get<2>(storage))), decltype(view1 | view3)>();
-    testing::StaticAssertTypeEq<decltype(view1.join(std::get<3>(std::as_const(storage)))), decltype(view1 | view4)>();
+    testing::StaticAssertTypeEq<decltype(view1 | std::get<2>(storage)), decltype(view1 | view3)>();
+    testing::StaticAssertTypeEq<decltype(view1 | std::get<3>(std::as_const(storage))), decltype(view1 | view4)>();
+    testing::StaticAssertTypeEq<decltype(view1 | std::get<2>(storage) | view4), decltype(view1 | view3 | view4)>();
 
 
     testing::StaticAssertTypeEq<entt::basic_view<entt::get_t<entt::storage<int>, const entt::storage<int>>, entt::exclude_t<const entt::storage<double>, entt::storage<float>>>, decltype(view1 | view2)>();
     testing::StaticAssertTypeEq<entt::basic_view<entt::get_t<entt::storage<int>, const entt::storage<int>>, entt::exclude_t<const entt::storage<double>, entt::storage<float>>>, decltype(view1 | view2)>();
     testing::StaticAssertTypeEq<entt::basic_view<entt::get_t<const entt::storage<int>, entt::storage<int>>, entt::exclude_t<entt::storage<float>, const entt::storage<double>>>, decltype(view2 | view1)>();
     testing::StaticAssertTypeEq<entt::basic_view<entt::get_t<const entt::storage<int>, entt::storage<int>>, entt::exclude_t<entt::storage<float>, const entt::storage<double>>>, decltype(view2 | view1)>();