diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index 9721f80ec..5c917409c 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -642,6 +642,21 @@ class basic_view, exclude_t, std::enable_if_t<(sizeof. return iterable{base_type::begin(), base_type::end()}; } + /** + * @brief Attaches a storage to the end of the view for iterating. + * + * @tparam OGet The type of the storage to attach to the view. + * @param other The storage to attach to the view. + * @return A new view with the given storage attached. + * @note This function only supports adding one storage, use @ref operator| to join two views instead. + * @sa operator| + */ + template + [[nodiscard]] auto join(OGet &other) const noexcept { + return internal::view_pack, exclude_t>>( + *this, basic_view, exclude_t<>>{other}, std::index_sequence_for{}, std::index_sequence_for{}, std::index_sequence_for{}, std::index_sequence_for<>{}); + } + /** * @brief Combines two views in a _more specific_ one. * @tparam OGet Element list of the view to combine with. @@ -1072,6 +1087,21 @@ class basic_view, exclude_t<>> } } + /** + * @brief Attaches a storage to the end of the view for iterating. + * + * @tparam OGet The type of the storage to attach to the view. + * @param other The storage to attach to the view. + * @return A new view with the given storage attached. + * @note This function only supports adding one storage, use @ref operator| to join two views instead. + * @sa operator| + */ + template + [[nodiscard]] auto join(OGet &other) const noexcept { + return internal::view_pack, exclude_t<>>>( + *this, basic_view, exclude_t<>>{other}, std::index_sequence_for{}, std::index_sequence_for<>{}, std::index_sequence_for{}, std::index_sequence_for<>{}); + } + /** * @brief Combines two views in a _more specific_ one. * @tparam OGet Element list of the view to combine with. diff --git a/test/entt/entity/view.cpp b/test/entt/entity/view.cpp index 93e4049e9..3f145bdbd 100644 --- a/test/entt/entity/view.cpp +++ b/test/entt/entity/view.cpp @@ -1540,6 +1540,10 @@ TEST(View, Pipe) { entt::basic_view view2{std::forward_as_tuple(std::as_const(std::get<0>(storage))), std::forward_as_tuple(std::get<4>(storage))}; entt::basic_view view3{std::get<2>(storage)}; entt::basic_view view4{std::get<3>(storage)}; + entt::basic_view view5{std::get<3>(std::as_const(storage))}; + + testing::StaticAssertTypeEq(storage))), decltype(view1 | view3)>(); + testing::StaticAssertTypeEq(std::as_const(storage)))), decltype(view1 | view5)>(); testing::StaticAssertTypeEq, const entt::storage>, entt::exclude_t, entt::storage>>, decltype(view1 | view2)>(); testing::StaticAssertTypeEq, entt::storage>, entt::exclude_t, const entt::storage>>, decltype(view2 | view1)>();