Skip to content

Commit cb36354

Browse files
committed
Fixes const iteration for chain()
Fixes ryanhaining#65
1 parent 334c715 commit cb36354

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

chain.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ namespace iter {
2525
// rather than a chain function, use a callable object to support
2626
// from_iterable
2727
class ChainMaker;
28+
29+
template <typename>
30+
struct AsTupleOfConstImpl;
31+
32+
template <typename... Ts>
33+
struct AsTupleOfConstImpl<std::tuple<Ts...>>
34+
: type_is<std::tuple<AsConst<Ts>...>> {};
35+
36+
template <typename T>
37+
using AsTupleOfConst = typename AsTupleOfConstImpl<T>::type;
2838
}
2939
}
3040

@@ -169,12 +179,12 @@ class iter::impl::Chained {
169179
{get_end(std::get<Is>(tup_))...}};
170180
}
171181

172-
Iterator<AsConst<TupType>> begin() const {
182+
Iterator<AsTupleOfConst<TupType>> begin() const {
173183
return {0, {get_begin(std::as_const(std::get<Is>(tup_)))...},
174184
{get_end(std::as_const(std::get<Is>(tup_)))...}};
175185
}
176186

177-
Iterator<AsConst<TupType>> end() const {
187+
Iterator<AsTupleOfConst<TupType>> end() const {
178188
return {sizeof...(Is), {get_end(std::as_const(std::get<Is>(tup_)))...},
179189
{get_end(std::as_const(std::get<Is>(tup_)))...}};
180190
}

test/test_chain.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "catch.hpp"
1111

1212
using iter::chain;
13-
using itertest::SolidInt;
1413
using itertest::BasicIterable;
14+
using itertest::SolidInt;
1515
using Vec = const std::vector<char>;
1616

1717
TEST_CASE("chain: three strings", "[chain]") {
@@ -28,8 +28,8 @@ TEST_CASE("chain: three strings", "[chain]") {
2828

2929
TEST_CASE("chain: const iteration", "[chain][const]") {
3030
std::string s1{"abc"};
31-
/* const */ std::string s2{"mno"};
32-
auto ch = chain(s1, s2, std::string{"xyz"});
31+
const std::string s2{"mno"};
32+
const auto ch = chain(s1, s2, std::string{"xyz"});
3333

3434
Vec v(std::begin(ch), std::end(ch));
3535
Vec vc{'a', 'b', 'c', 'm', 'n', 'o', 'x', 'y', 'z'};
@@ -309,8 +309,8 @@ template <typename T>
309309
using ImpT2 = decltype(chain.from_iterable(std::declval<T>()));
310310
TEST_CASE("chain.from_iterable: has correct ctor and assign ops",
311311
"[chain.from_iterable]") {
312-
REQUIRE(itertest::IsMoveConstructibleOnly<ImpT2<std::vector<std::string>>>::
313-
value);
314-
REQUIRE(itertest::IsMoveConstructibleOnly<ImpT2<std::vector<std::string>&>>::
315-
value);
312+
REQUIRE(itertest::IsMoveConstructibleOnly<
313+
ImpT2<std::vector<std::string>>>::value);
314+
REQUIRE(itertest::IsMoveConstructibleOnly<
315+
ImpT2<std::vector<std::string>&>>::value);
316316
}

0 commit comments

Comments
 (0)