* @brief Check that different callable types are accepted by the thread pool. */
| 1351 | * @brief Check that different callable types are accepted by the thread pool. |
| 1352 | */ |
| 1353 | void check_callables() |
| 1354 | { |
| 1355 | BS::thread_pool pool; |
| 1356 | |
| 1357 | logln("Checking normal function..."); |
| 1358 | pool.submit_task(normal_func).wait(); |
| 1359 | check(check_callables_flag); |
| 1360 | |
| 1361 | logln("Checking function pointer..."); |
| 1362 | check_callables_flag = false; |
| 1363 | void (*const func_ptr)() = normal_func; // NOLINT(misc-const-correctness) |
| 1364 | pool.submit_task(func_ptr).wait(); |
| 1365 | check(check_callables_flag); |
| 1366 | |
| 1367 | logln("Checking pointer to static member function..."); |
| 1368 | check_callables_flag = false; |
| 1369 | auto member_func_ptr = has_member_function::member_function; |
| 1370 | pool.submit_task(member_func_ptr).wait(); |
| 1371 | check(check_callables_flag); |
| 1372 | |
| 1373 | logln("Checking lambda expression..."); |
| 1374 | check_callables_flag = false; |
| 1375 | const auto lambda = [] |
| 1376 | { |
| 1377 | check_callables_flag = true; |
| 1378 | }; |
| 1379 | pool.submit_task(lambda).wait(); |
| 1380 | check(check_callables_flag); |
| 1381 | |
| 1382 | logln("Checking std::function..."); |
| 1383 | check_callables_flag = false; |
| 1384 | const std::function<void()> function = [] |
| 1385 | { |
| 1386 | check_callables_flag = true; |
| 1387 | }; |
| 1388 | pool.submit_task(function).wait(); |
| 1389 | check(check_callables_flag); |
| 1390 | |
| 1391 | #ifdef __cpp_lib_move_only_function |
| 1392 | logln("Checking std::move_only_function..."); |
| 1393 | check_callables_flag = false; |
| 1394 | std::move_only_function<void()> move_only_function = [] |
| 1395 | { |
| 1396 | check_callables_flag = true; |
| 1397 | }; |
| 1398 | pool.submit_task(std::move(move_only_function)).wait(); |
| 1399 | check(check_callables_flag); |
| 1400 | #else |
| 1401 | logln_ansi(ansi_info, "Note: std::move_only_function not available, skipping the corresponding test."); |
| 1402 | #endif |
| 1403 | |
| 1404 | logln("Checking std::bind..."); |
| 1405 | check_callables_flag = false; |
| 1406 | const auto lambda_for_bind = [](std::atomic<bool>& flag) |
| 1407 | { |
| 1408 | flag = true; |
| 1409 | }; |
| 1410 | pool.submit_task(std::bind(lambda_for_bind, std::ref(check_callables_flag))).wait(); |
no test coverage detected