diff --git a/src/util/range.h b/src/util/range.h index ea8f47b02d..b7de67dfd6 100644 --- a/src/util/range.h +++ b/src/util/range.h @@ -208,8 +208,8 @@ struct concat_iteratort public: using difference_type = typename first_iteratort::difference_type; using value_type = typename first_iteratort::value_type; - using pointer = const value_type *; - using reference = const value_type &; + using pointer = typename first_iteratort::pointer; + using reference = typename first_iteratort::reference; using iterator_category = std::forward_iterator_tag; static_assert( @@ -245,14 +245,14 @@ public: return tmp; } - value_type &operator*() + reference operator*() { if(first_begin == first_end) return *second_begin; return *first_begin; } - value_type *operator->() + pointer operator->() { if(first_begin == first_end) return &(*second_begin); diff --git a/unit/util/range.cpp b/unit/util/range.cpp index 1b83c11e48..1cf8f95bc1 100644 --- a/unit/util/range.cpp +++ b/unit/util/range.cpp @@ -76,6 +76,18 @@ SCENARIO("range tests", "[core][util][range]") REQUIRE(odds == expected_odds); } } + GIVEN("Two const vectors of ints") + { + const std::vector input1{1, 2}; + const std::vector input2{3, 4}; + THEN("Concat the vectors using range.") + { + auto range = make_range(input1).concat(make_range(input2)); + const std::vector output{range.begin(), range.end()}; + const std::vector expected{1, 2, 3, 4}; + REQUIRE(output == expected); + }; + } } class move_onlyt