-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathfor_each_n_args.cpp
More file actions
40 lines (33 loc) · 1.09 KB
/
for_each_n_args.cpp
File metadata and controls
40 lines (33 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "detail/tuple_types.hpp"
#include <stdx/for_each_n_args.hpp>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("default to unary function", "[for_each_n_args]") {
auto sum = 0;
auto f = [&](int x) { sum += x; };
stdx::for_each_n_args(f, 1, 2, 3);
CHECK(sum == 6);
}
TEST_CASE("binary function", "[for_each_n_args]") {
auto sum = 0;
auto f = [&](int x, int y) { sum += x * y; };
stdx::for_each_n_args<2>(f, 2, 3, 3, 4);
CHECK(sum == 18);
}
TEST_CASE("generic function", "[for_each_n_args]") {
auto sum = 0;
auto f = [&](auto x, auto y) { sum += x * y; };
stdx::for_each_n_args<2>(f, 2, 3, 3, 4);
CHECK(sum == 18);
}
TEST_CASE("move-only arguments", "[for_each_n_args]") {
auto sum = 0;
auto f = [&](move_only x) { sum += x.value; };
stdx::for_each_n_args(f, move_only{1}, move_only{2}, move_only{3});
CHECK(sum == 6);
}
TEST_CASE("default arguments", "[for_each_n_args]") {
auto sum = 0;
auto f = [&](int x, int y, int z = 42) { sum += x * y + z; };
stdx::for_each_n_args<2>(f, 2, 3, 3, 4);
CHECK(sum == 42 + 42 + 18);
}