@@ -92,10 +92,13 @@ constexpr void test_basic_bindings() {
92
92
}
93
93
94
94
{ // Basic tests with fundamental types
95
- int n = 2 ;
96
- int m = 1 ;
97
- auto add = [](int x, int y) { return x + y; };
98
- auto add_n = [](int a, int b, int c, int d, int e, int f) { return a + b + c + d + e + f; };
95
+ int n = 2 ;
96
+ int m = 1 ;
97
+ int sum = 0 ;
98
+ auto add = [](int x, int y) { return x + y; };
99
+ auto add_n = [](int a, int b, int c, int d, int e, int f) { return a + b + c + d + e + f; };
100
+ auto add_ref = [&](int x, int y) -> int & { return sum = x + y; };
101
+ auto add_rref = [&](int x, int y) -> int && { return std::move (sum = x + y); };
99
102
100
103
auto a = std::bind_back (add, m, n);
101
104
assert (a () == 3 );
@@ -106,6 +109,14 @@ constexpr void test_basic_bindings() {
106
109
auto c = std::bind_back (add_n, n, m);
107
110
assert (c (1 , 1 , 1 , 1 ) == 7 );
108
111
112
+ auto d = std::bind_back (add_ref, n, m);
113
+ std::same_as<int &> decltype (auto ) dresult (d ());
114
+ assert (dresult == 3 );
115
+
116
+ auto e = std::bind_back (add_rref, n, m);
117
+ std::same_as<int &&> decltype (auto ) eresult (e ());
118
+ assert (eresult == 3 );
119
+
109
120
auto f = std::bind_back (add, n);
110
121
assert (f (3 ) == 5 );
111
122
@@ -114,6 +125,14 @@ constexpr void test_basic_bindings() {
114
125
115
126
auto h = std::bind_back (add_n, 1 , 1 , 1 );
116
127
assert (h (2 , 2 , 2 ) == 9 );
128
+
129
+ auto i = std::bind_back (add_ref, n);
130
+ std::same_as<int &> decltype (auto ) iresult (i (5 ));
131
+ assert (iresult == 7 );
132
+
133
+ auto j = std::bind_back (add_rref, m);
134
+ std::same_as<int &&> decltype (auto ) jresult (j (4 ));
135
+ assert (jresult == 5 );
117
136
}
118
137
}
119
138
0 commit comments