diff --git a/include/flux/op/set_adaptors.hpp b/include/flux/op/set_adaptors.hpp index fa07ca55..f6b9aa04 100644 --- a/include/flux/op/set_adaptors.hpp +++ b/include/flux/op/set_adaptors.hpp @@ -128,7 +128,7 @@ struct set_union_adaptor bounded_sequence && bounded_sequence static constexpr auto last(Self& self) -> cursor_type { - return cursor_type{flux::last(self.base1_), flux::last(self.base2_)}; + return cursor_type{flux::last(self.base1_), flux::last(self.base2_), cursor_type::second}; } template @@ -558,4 +558,4 @@ inline constexpr auto set_intersection = detail::set_intersection_fn{}; } // namespace flux -#endif // namespace FLUX_OP_SET_ADAPTORS_HPP_INCLUDED \ No newline at end of file +#endif // namespace FLUX_OP_SET_ADAPTORS_HPP_INCLUDED diff --git a/test/test_set_adaptors.cpp b/test/test_set_adaptors.cpp index 4d20cf53..c06a11b3 100644 --- a/test/test_set_adaptors.cpp +++ b/test/test_set_adaptors.cpp @@ -153,6 +153,20 @@ constexpr bool test_set_union() STATIC_CHECK(check_equal(union_seq, {1.0, 2.0, 3.0, 4.0, 5.0, 6.0})); } + // test cursor iteration + { + int arr1[] = {0, 2, 4, 6}; + int arr2[] = { 1, 3, 5}; + auto union_seq = flux::set_union(flux::ref(arr1), flux::ref(arr2)); + + auto first = flux::first(union_seq); + auto last = flux::last(union_seq); + while (first != last) { + flux::inc(union_seq, first); + } + STATIC_CHECK(first == last); + } + return true; } @@ -618,4 +632,4 @@ TEST_CASE("set_intersection") { bool result = test_set_intersection(); REQUIRE(result); -} \ No newline at end of file +} diff --git a/test/test_to.cpp b/test/test_to.cpp index f29c597e..ae1e4a75 100644 --- a/test/test_to.cpp +++ b/test/test_to.cpp @@ -211,6 +211,14 @@ TEST_CASE("to") CHECK(check_equal(vec, {"The", "quick", "brown", "fox"})); } + + SECTION("from set_union adaptor") + { + auto union_seq = flux::set_union(std::array{1,2,3}, std::array{4,5}); + auto vec = flux::to>(union_seq); + + CHECK(check_equal(vec, {1,2,3,4,5})); + } } SECTION("...using CTAD") @@ -340,4 +348,4 @@ TEST_CASE("to") } } } -} \ No newline at end of file +}