Skip to content

Commit 020f99d

Browse files
author
Ryan Haining
committed
Adds support for move-only callables in filterfalse
Issue #89
1 parent 0fc1cf1 commit 020f99d

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

cppitertools/filterfalse.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class iter::impl::FilterFalsed
4848
friend FilterFalseFn;
4949
FilterFalsed(FilterFunc in_filter_func, Container&& in_container)
5050
: Filtered<PredicateFlipper<FilterFunc>, Container>(
51-
{in_filter_func}, std::forward<Container>(in_container)) {}
51+
{std::move(in_filter_func)},
52+
std::forward<Container>(in_container)) {}
5253
};
5354

5455
#endif

test/test_filterfalse.cpp

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,46 @@ using Vec = const std::vector<int>;
1313
TEST_CASE("filterfalse: handles different callable types", "[filterfalse]") {
1414
Vec ns = {1, 2, 5, 6, 3, 1, 7, -1, 5};
1515
Vec vc = {5, 6, 7, 5};
16+
std::vector<int> v;
1617
SECTION("with function pointer") {
1718
auto f = filterfalse(less_than_five, ns);
18-
Vec v(std::begin(f), std::end(f));
19-
REQUIRE(v == vc);
19+
v = Vec(std::begin(f), std::end(f));
2020
}
2121

2222
SECTION("with callable object") {
23-
std::vector<int> v;
24-
SECTION("Normal call") {
25-
auto f = filterfalse(LessThanValue{5}, ns);
26-
v.assign(std::begin(f), std::end(f));
23+
auto f = filterfalse(LessThanValue{5}, ns);
24+
v = Vec(std::begin(f), std::end(f));
25+
}
26+
27+
SECTION("with lvalue callable object") {
28+
auto lt = LessThanValue{5};
29+
SECTION("normal call") {
30+
auto f = filterfalse(lt, ns);
31+
v = Vec(std::begin(f), std::end(f));
32+
}
33+
SECTION("pipe") {
34+
auto f = ns | filterfalse(lt);
35+
v = Vec(std::begin(f), std::end(f));
2736
}
28-
SECTION("Pipe") {
29-
auto f = ns | filterfalse(LessThanValue{5});
30-
v.assign(std::begin(f), std::end(f));
37+
}
38+
39+
SECTION("with move-only callable object") {
40+
SECTION("normal call") {
41+
auto f = filterfalse(MoveOnlyLessThanValue{5}, ns);
42+
v = Vec(std::begin(f), std::end(f));
43+
}
44+
SECTION("pipe") {
45+
auto f = ns | filterfalse(MoveOnlyLessThanValue{5});
46+
v = Vec(std::begin(f), std::end(f));
3147
}
32-
REQUIRE(v == vc);
3348
}
3449

3550
SECTION("with lambda") {
3651
auto ltf = [](int i) { return i < 5; };
3752
auto f = filterfalse(ltf, ns);
38-
Vec v(std::begin(f), std::end(f));
39-
REQUIRE(v == vc);
53+
v = Vec(std::begin(f), std::end(f));
4054
}
55+
REQUIRE(v == vc);
4156
}
4257

4358
TEST_CASE("filterfalse: handles pointer to member", "[filterfalse]") {

0 commit comments

Comments
 (0)