diff --git a/chain.hpp b/chain.hpp index d289a6a3..23d1e054 100644 --- a/chain.hpp +++ b/chain.hpp @@ -25,6 +25,16 @@ namespace iter { // rather than a chain function, use a callable object to support // from_iterable class ChainMaker; + + template + struct AsTupleOfConstImpl; + + template + struct AsTupleOfConstImpl> + : type_is...>> {}; + + template + using AsTupleOfConst = typename AsTupleOfConstImpl::type; } } @@ -169,12 +179,12 @@ class iter::impl::Chained { {get_end(std::get(tup_))...}}; } - Iterator> begin() const { + Iterator> begin() const { return {0, {get_begin(std::as_const(std::get(tup_)))...}, {get_end(std::as_const(std::get(tup_)))...}}; } - Iterator> end() const { + Iterator> end() const { return {sizeof...(Is), {get_end(std::as_const(std::get(tup_)))...}, {get_end(std::as_const(std::get(tup_)))...}}; } diff --git a/test/test_chain.cpp b/test/test_chain.cpp index 6caabe3f..b4b77cf2 100644 --- a/test/test_chain.cpp +++ b/test/test_chain.cpp @@ -10,8 +10,8 @@ #include "catch.hpp" using iter::chain; -using itertest::SolidInt; using itertest::BasicIterable; +using itertest::SolidInt; using Vec = const std::vector; TEST_CASE("chain: three strings", "[chain]") { @@ -28,8 +28,8 @@ TEST_CASE("chain: three strings", "[chain]") { TEST_CASE("chain: const iteration", "[chain][const]") { std::string s1{"abc"}; - /* const */ std::string s2{"mno"}; - auto ch = chain(s1, s2, std::string{"xyz"}); + const std::string s2{"mno"}; + const auto ch = chain(s1, s2, std::string{"xyz"}); Vec v(std::begin(ch), std::end(ch)); Vec vc{'a', 'b', 'c', 'm', 'n', 'o', 'x', 'y', 'z'}; @@ -309,8 +309,8 @@ template using ImpT2 = decltype(chain.from_iterable(std::declval())); TEST_CASE("chain.from_iterable: has correct ctor and assign ops", "[chain.from_iterable]") { - REQUIRE(itertest::IsMoveConstructibleOnly>>:: - value); - REQUIRE(itertest::IsMoveConstructibleOnly&>>:: - value); + REQUIRE(itertest::IsMoveConstructibleOnly< + ImpT2>>::value); + REQUIRE(itertest::IsMoveConstructibleOnly< + ImpT2&>>::value); }