Skip to content

Commit 47d0a43

Browse files
committed
view: join -> operator|
1 parent abbb3bf commit 47d0a43

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/entt/entity/view.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -644,13 +644,12 @@ class basic_view<get_t<Get...>, exclude_t<Exclude...>, std::enable_if_t<(sizeof.
644644

645645
/**
646646
* @brief Combines a view and a storage in _more specific_ view.
647-
* @tparam OGet Type of storage to join the view with.
648-
* @param other The storage for the type to join the view with.
647+
* @tparam OGet Type of storage to combine the view with.
648+
* @param other The storage for the type to combine the view with.
649649
* @return A more specific view.
650650
*/
651651
template<typename OGet>
652-
[[nodiscard]] auto join(OGet &other) const noexcept {
653-
static_assert(std::is_base_of_v<common_type, OGet>, "Unexpected storage type");
652+
[[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 {
654653
return *this | basic_view<get_t<OGet>, exclude_t<>>{other};
655654
}
656655

@@ -1086,13 +1085,12 @@ class basic_view<get_t<Get>, exclude_t<>>
10861085

10871086
/**
10881087
* @brief Combines a view and a storage in _more specific_ view.
1089-
* @tparam OGet Type of storage to join the view with.
1090-
* @param other The storage for the type to join the view with.
1088+
* @tparam OGet Type of storage to combine the view with.
1089+
* @param other The storage for the type to combine the view with.
10911090
* @return A more specific view.
10921091
*/
10931092
template<typename OGet>
1094-
[[nodiscard]] auto join(OGet &other) const noexcept {
1095-
static_assert(std::is_base_of_v<common_type, OGet>, "Unexpected storage type");
1093+
[[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 {
10961094
return *this | basic_view<get_t<OGet>, exclude_t<>>{other};
10971095
}
10981096

test/entt/entity/view.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,8 +1541,9 @@ TEST(View, Pipe) {
15411541
entt::basic_view view3{std::get<2>(storage)};
15421542
entt::basic_view view4{std::as_const(std::get<3>(storage))};
15431543

1544-
testing::StaticAssertTypeEq<decltype(view1.join(std::get<2>(storage))), decltype(view1 | view3)>();
1545-
testing::StaticAssertTypeEq<decltype(view1.join(std::get<3>(std::as_const(storage)))), decltype(view1 | view4)>();
1544+
testing::StaticAssertTypeEq<decltype(view1 | std::get<2>(storage)), decltype(view1 | view3)>();
1545+
testing::StaticAssertTypeEq<decltype(view1 | std::get<3>(std::as_const(storage))), decltype(view1 | view4)>();
1546+
testing::StaticAssertTypeEq<decltype(view1 | std::get<2>(storage) | view4), decltype(view1 | view3 | view4)>();
15461547

15471548
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)>();
15481549
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)>();

0 commit comments

Comments
 (0)