MCPcopy Create free account
hub / github.com/davisking/dlib / test_lambdas

Function test_lambdas

dlib/test/invoke.cpp:145–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143 // ----------------------------------------------------------------------------------------
144
145 void test_lambdas()
146 {
147 {
148 const auto f = [](int, float*, std::string&) -> long {return 1;};
149
150 static_assert(std::is_same<dlib::callable_args<decltype(f)>,
151 dlib::types_<int, float*, std::string&>
152 >::value, "make this correct");
153
154 static_assert(dlib::callable_nargs<decltype(f)>::value == 3, "bad");
155
156 static_assert(std::is_same<dlib::callable_arg<0, decltype(f)>,
157 int>::value, "make this correct");
158
159 static_assert(std::is_same<dlib::callable_arg<1, decltype(f)>,
160 float*>::value, "make this correct");
161
162 static_assert(std::is_same<dlib::callable_arg<2, decltype(f)>,
163 std::string&>::value, "make this correct");
164
165 static_assert(std::is_same<dlib::callable_return<decltype(f)>,
166 long>::value, "make this correct");
167
168 static_assert(is_callable<decltype(f)>::value, "bad");
169 }
170
171 {
172 std::string str = run1_str4;
173 dlib::invoke([](int i, std::string ref1, const std::string& ref2, const std::string& ref3, std::string& ref4) {
174 DLIB_TEST(i > 0);
175 DLIB_TEST(ref1 == run1_str1);
176 DLIB_TEST(ref2 == run1_str2);
177 DLIB_TEST(ref3 == run1_str3);
178 DLIB_TEST(ref4 == run1_str4);
179 ref4 = run1_str5;
180 }, 1, run1_str1, run1_str2, std::cref(run1_str3), std::ref(str));
181 DLIB_TEST(str == run1_str5);
182 }
183
184 {
185 std::string str = run1_str4;
186 dlib::apply([](int i, std::string ref1, const std::string& ref2, const std::string& ref3, std::string& ref4) {
187 DLIB_TEST(i > 0);
188 DLIB_TEST(ref1 == run1_str1);
189 DLIB_TEST(ref2 == run1_str2);
190 DLIB_TEST(ref3 == run1_str3);
191 DLIB_TEST(ref4 == run1_str4);
192 ref4 = run1_str5;
193 }, std::make_tuple(1, run1_str1, run1_str2, std::cref(run1_str3), std::ref(str)));
194 DLIB_TEST(str == run1_str5);
195 }
196
197 {
198 for (int i = -10 ; i <= 10 ; i++)
199 {
200 for (int j = -10 ; j <= 10 ; j++)
201 {
202 DLIB_TEST(dlib::invoke([](int i, int j) {return i + j;}, i, j) == (i+j));

Callers 1

perform_testMethod · 0.85

Calls 5

invokeFunction · 0.85
crefFunction · 0.85
refFunction · 0.85
applyFunction · 0.85
make_tupleFunction · 0.85

Tested by

no test coverage detected