Skip to content

Commit 256fd81

Browse files
committed
Rename ranget::value_typet to ranget::value_type
Algorithms which are written expecting a STL container may reference a `value_type` member, as this is the name of the member in STL containers. Therefore this needs to be named the same way in `ranget` in order to be compatible with such algorithms. This commit includes a unit test of `ranget` having correct the `value_type` defined.
1 parent 6060a87 commit 256fd81

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/util/range.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,14 @@ template <typename iteratort>
311311
struct ranget final
312312
{
313313
public:
314-
using value_typet = typename iteratort::value_type;
314+
using value_type = typename iteratort::value_type;
315315

316316
ranget(iteratort begin, iteratort end) : begin_value(begin), end_value(end)
317317
{
318318
}
319319

320320
ranget<filter_iteratort<iteratort>>
321-
filter(std::function<bool(const value_typet &)> f)
321+
filter(std::function<bool(const value_type &)> f)
322322
{
323323
auto shared_f = std::make_shared<decltype(f)>(std::move(f));
324324
filter_iteratort<iteratort> filter_begin(shared_f, begin(), end());
@@ -335,9 +335,9 @@ struct ranget final
335335
template <typename functiont>
336336
auto map(functiont &&f) -> ranget<map_iteratort<
337337
iteratort,
338-
typename std::result_of<functiont(value_typet)>::type>>
338+
typename std::result_of<functiont(value_type)>::type>>
339339
{
340-
using outputt = typename std::result_of<functiont(value_typet)>::type;
340+
using outputt = typename std::result_of<functiont(value_type)>::type;
341341
auto shared_f = std::make_shared<
342342
std::function<outputt(const typename iteratort::value_type &)>>(
343343
std::forward<functiont>(f));

unit/util/range.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ Author: Romain Brenguier, [email protected]
1111
#include <testing-utils/catch.hpp>
1212
#include <util/range.h>
1313

14+
/// Trivial example template function requiring a container to have a
15+
/// `value_type`.
16+
template <typename containert>
17+
typename containert::value_type front(containert container)
18+
{
19+
return *container.begin();
20+
}
21+
1422
SCENARIO("range tests", "[core][util][range]")
1523
{
1624
GIVEN("A vector with three strings")
@@ -75,6 +83,18 @@ SCENARIO("range tests", "[core][util][range]")
7583
const std::vector<int> expected_odds{1, 3};
7684
REQUIRE(odds == expected_odds);
7785
}
86+
THEN(
87+
"The unit testing template function requiring `value_type` works with "
88+
"`std::vector`.")
89+
{
90+
REQUIRE(front(input) == 1);
91+
}
92+
THEN(
93+
"A range can be used with a template function expecting a container "
94+
"which has a `value_type`.")
95+
{
96+
REQUIRE(front(make_range(input)) == 1);
97+
}
7898
}
7999
GIVEN("Two const vectors of ints")
80100
{

0 commit comments

Comments
 (0)