view: join -> operator|

This commit is contained in:
Michele Caini
2024-12-20 09:59:55 +01:00
parent abbb3bf7ff
commit 47d0a4328f
2 changed files with 9 additions and 10 deletions

View File

@@ -644,13 +644,12 @@ public:
/**
* @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.
*/
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};
}
@@ -1086,13 +1085,12 @@ public:
/**
* @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.
*/
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};
}

View File

@@ -1541,8 +1541,9 @@ TEST(View, Pipe) {
entt::basic_view view3{std::get<2>(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<const entt::storage<int>, entt::storage<int>>, entt::exclude_t<entt::storage<float>, const entt::storage<double>>>, decltype(view2 | view1)>();