11
11
#include < functional>
12
12
#include < list>
13
13
#include < memory>
14
+ #include < tuple>
14
15
#include < type_traits>
15
16
#include < utility>
16
17
@@ -49,15 +50,16 @@ TEST_CASE("Showing that direct constructor is not desirable.")
49
50
with functions is treated
50
51
just like an lvalue... */
51
52
52
- make_scope_guard (inc); // ... but the BEST is really to use the make function
53
+ std::ignore = make_scope_guard (inc); // ... but the BEST is really to use the
54
+ // make function
53
55
}
54
56
55
57
/* --- Plain functions, lvalues, rvalues, plain references, consts --- */
56
58
57
59
// //////////////////////////////////////////////////////////////////////////////
58
60
TEST_CASE (" A plain function can be used to create a scope_guard." )
59
61
{
60
- make_scope_guard (inc);
62
+ std::ignore = make_scope_guard (inc);
61
63
}
62
64
63
65
// //////////////////////////////////////////////////////////////////////////////
@@ -103,7 +105,7 @@ TEST_CASE("An lvalue reference to a plain function can be used to create a "
103
105
" scope_guard." )
104
106
{
105
107
auto & inc_ref = inc;
106
- make_scope_guard (inc_ref);
108
+ std::ignore = make_scope_guard (inc_ref);
107
109
}
108
110
109
111
// //////////////////////////////////////////////////////////////////////////////
@@ -153,7 +155,7 @@ TEST_CASE("An lvalue const reference to a plain function can be used to create "
153
155
" a scope_guard." )
154
156
{
155
157
const auto & inc_ref = inc;
156
- make_scope_guard (inc_ref);
158
+ std::ignore = make_scope_guard (inc_ref);
157
159
}
158
160
159
161
// //////////////////////////////////////////////////////////////////////////////
@@ -208,7 +210,7 @@ type, which is treated as lvalue reference. */
208
210
TEST_CASE (" An rvalue reference to a plain function can be used to create a "
209
211
" scope_guard." )
210
212
{
211
- make_scope_guard (std::move (inc)); // rvalue ref to function treated as lvalue
213
+ std::ignore = make_scope_guard (std::move (inc)); // rvalue ref to function treated as lvalue
212
214
}
213
215
214
216
// //////////////////////////////////////////////////////////////////////////////
@@ -257,7 +259,7 @@ TEST_CASE("A dismissed rvalue-reference-to-plain-function-based scope_guard "
257
259
TEST_CASE (" A reference wrapper to a plain function can be used to create a "
258
260
" scope_guard." )
259
261
{
260
- make_scope_guard (std::ref (inc));
262
+ std::ignore = make_scope_guard (std::ref (inc));
261
263
}
262
264
263
265
// //////////////////////////////////////////////////////////////////////////////
@@ -302,7 +304,7 @@ TEST_CASE("A dismissed reference-wrapper-to-plain-function-based scope_guard "
302
304
TEST_CASE (" A const reference wrapper to a plain function can be used to create "
303
305
" a scope_guard." )
304
306
{
305
- make_scope_guard (std::cref (inc));
307
+ std::ignore = make_scope_guard (std::cref (inc));
306
308
}
307
309
308
310
// //////////////////////////////////////////////////////////////////////////////
@@ -351,7 +353,7 @@ TEST_CASE("An lvalue plain function pointer can be used to create a "
351
353
" scope_guard." )
352
354
{
353
355
const auto fp = &inc;
354
- make_scope_guard (fp);
356
+ std::ignore = make_scope_guard (fp);
355
357
}
356
358
357
359
// //////////////////////////////////////////////////////////////////////////////
@@ -399,7 +401,7 @@ TEST_CASE("A dismissed lvalue-plain-function-pointer-based scope_guard does "
399
401
TEST_CASE (" An rvalue plain function pointer can be used to create a "
400
402
" scope_guard." )
401
403
{
402
- make_scope_guard (&inc);
404
+ std::ignore = make_scope_guard (&inc);
403
405
}
404
406
405
407
// //////////////////////////////////////////////////////////////////////////////
@@ -446,7 +448,7 @@ TEST_CASE("An lvalue reference to a plain function pointer can be used to "
446
448
{
447
449
const auto fp = &inc;
448
450
const auto & fp_ref = fp;
449
- make_scope_guard (fp_ref);
451
+ std::ignore = make_scope_guard (fp_ref);
450
452
}
451
453
452
454
// //////////////////////////////////////////////////////////////////////////////
@@ -498,7 +500,7 @@ TEST_CASE("An rvalue reference to a plain function pointer can be used to "
498
500
" create a scope_guard." )
499
501
{
500
502
const auto fp = &inc;
501
- make_scope_guard (std::move (fp));
503
+ std::ignore = make_scope_guard (std::move (fp));
502
504
}
503
505
504
506
// //////////////////////////////////////////////////////////////////////////////
@@ -579,7 +581,7 @@ TEST_CASE("An lvalue std::function that wraps a regular function can be used "
579
581
" to create a scope_guard." )
580
582
{
581
583
const auto stdf = make_std_function (inc);
582
- make_scope_guard (stdf);
584
+ std::ignore = make_scope_guard (stdf);
583
585
}
584
586
585
587
// //////////////////////////////////////////////////////////////////////////////
@@ -629,8 +631,8 @@ TEST_CASE("A dismissed scope_guard that was created with a "
629
631
TEST_CASE (" An rvalue std::function that wraps a regular function can be used "
630
632
" to create a scope_guard." )
631
633
{
632
- make_scope_guard (make_std_function (inc));
633
- make_scope_guard (std::function<void ()>{inc});
634
+ std::ignore = make_scope_guard (make_std_function (inc));
635
+ std::ignore = make_scope_guard (std::function<void ()>{inc});
634
636
}
635
637
636
638
// //////////////////////////////////////////////////////////////////////////////
@@ -680,7 +682,7 @@ TEST_CASE("An lvalue reference to a std::function that wraps a regular "
680
682
{
681
683
const auto stdf = make_std_function (inc);
682
684
const auto & stdf_ref = stdf;
683
- make_scope_guard (stdf_ref);
685
+ std::ignore = make_scope_guard (stdf_ref);
684
686
}
685
687
686
688
// //////////////////////////////////////////////////////////////////////////////
@@ -735,7 +737,7 @@ TEST_CASE("An rvalue reference to a std::function that wraps a regular "
735
737
" function can be used to create a scope_guard." )
736
738
{
737
739
const auto stdf = make_std_function (inc);
738
- make_scope_guard (std::move (stdf));
740
+ std::ignore = make_scope_guard (std::move (stdf));
739
741
}
740
742
741
743
// //////////////////////////////////////////////////////////////////////////////
@@ -795,7 +797,7 @@ namespace
795
797
TEST_CASE (" A lambda function with no capture can be used to create a "
796
798
" scope_guard." )
797
799
{
798
- make_scope_guard ([]()noexcept {});
800
+ std::ignore = make_scope_guard ([]()noexcept {});
799
801
}
800
802
801
803
// //////////////////////////////////////////////////////////////////////////////
@@ -840,7 +842,8 @@ TEST_CASE("A lambda function with capture can be used to create a scope_guard.")
840
842
{
841
843
auto f = 0 .0f ;
842
844
const auto i = -1 ;
843
- make_scope_guard ([&f, i]()noexcept { f = static_cast <float >(*&i); });
845
+ std::ignore = make_scope_guard ([&f, i]() noexcept
846
+ { f = static_cast <float >(*&i); });
844
847
}
845
848
846
849
// //////////////////////////////////////////////////////////////////////////////
@@ -891,7 +894,7 @@ TEST_CASE("A const lambda function with capture can be used to create a "
891
894
auto f = 0 .0f ;
892
895
const auto i = -1 ;
893
896
const auto lambda = [&f, i]() noexcept { f = static_cast <float >(*&i); };
894
- make_scope_guard (lambda);
897
+ std::ignore = make_scope_guard (lambda);
895
898
}
896
899
897
900
// //////////////////////////////////////////////////////////////////////////////
@@ -987,7 +990,7 @@ TEST_CASE("A dismissed scope_guard that was created with a "
987
990
TEST_CASE (" A lambda function calling a std::function can be used to create a "
988
991
" scope_guard." )
989
992
{
990
- make_scope_guard ([]()noexcept { make_std_function (inc)(); });
993
+ std::ignore = make_scope_guard ([]()noexcept { make_std_function (inc)(); });
991
994
}
992
995
993
996
// //////////////////////////////////////////////////////////////////////////////
@@ -1019,7 +1022,7 @@ TEST_CASE("A scope_guard created with a std::function-calling lambda calls "
1019
1022
TEST_CASE (" A std::function wrapping a lambda function can be used to create a "
1020
1023
" scope_guard." )
1021
1024
{
1022
- make_scope_guard (std::function<void ()>([](){}));
1025
+ std::ignore = make_scope_guard (std::function<void ()>([](){}));
1023
1026
}
1024
1027
1025
1028
// //////////////////////////////////////////////////////////////////////////////
@@ -1042,7 +1045,7 @@ TEST_CASE("A scope_guard created with a lambda-wrapping std::function calls "
1042
1045
TEST_CASE (" A bound function can be used to create a scope_guard." )
1043
1046
{
1044
1047
auto boundf_count = 0u ;
1045
- make_scope_guard (std::bind (incc, std::ref (boundf_count)));
1048
+ std::ignore = make_scope_guard (std::bind (incc, std::ref (boundf_count)));
1046
1049
}
1047
1050
1048
1051
// //////////////////////////////////////////////////////////////////////////////
@@ -1080,7 +1083,7 @@ TEST_CASE("A dismissed bound-function-based scope_guard does not execute its "
1080
1083
// //////////////////////////////////////////////////////////////////////////////
1081
1084
TEST_CASE (" A bound lambda can be used to create a scope_guard." )
1082
1085
{
1083
- make_scope_guard (std::bind ([](int /* unused*/ ){}, 42 ));
1086
+ std::ignore = make_scope_guard (std::bind ([](int /* unused*/ ){}, 42 ));
1084
1087
}
1085
1088
1086
1089
// //////////////////////////////////////////////////////////////////////////////
@@ -1135,7 +1138,7 @@ namespace
1135
1138
// //////////////////////////////////////////////////////////////////////////////
1136
1139
TEST_CASE (" A stateless custom functor can be used to create a scope_guard" )
1137
1140
{
1138
- make_scope_guard (StatelessFunctor{});
1141
+ std::ignore = make_scope_guard (StatelessFunctor{});
1139
1142
}
1140
1143
1141
1144
// //////////////////////////////////////////////////////////////////////////////
@@ -1156,7 +1159,7 @@ TEST_CASE("A stateless-custom-functor-based scope_guard calls the functor "
1156
1159
TEST_CASE (" A stateful custom functor can be used to create a scope_guard" )
1157
1160
{
1158
1161
auto u = 123u ;
1159
- make_scope_guard (StatefulFunctor{u});
1162
+ std::ignore = make_scope_guard (StatefulFunctor{u});
1160
1163
}
1161
1164
1162
1165
// //////////////////////////////////////////////////////////////////////////////
@@ -1177,7 +1180,7 @@ TEST_CASE("A stateful-custom-functor-based scope_guard calls the functor "
1177
1180
TEST_CASE (" A const custom functor can be used to create a scope_guard" )
1178
1181
{
1179
1182
const auto fun = StatelessFunctor{};
1180
- make_scope_guard (fun);
1183
+ std::ignore = make_scope_guard (fun);
1181
1184
}
1182
1185
1183
1186
// //////////////////////////////////////////////////////////////////////////////
@@ -1201,7 +1204,7 @@ TEST_CASE("An lvalue reference to a noncopyable and nonmovable functor can be "
1201
1204
{
1202
1205
nocopy_nomove ncnm{};
1203
1206
const auto & ncnm_ref = ncnm;
1204
- make_scope_guard (ncnm_ref);
1207
+ std::ignore = make_scope_guard (ncnm_ref);
1205
1208
}
1206
1209
1207
1210
// //////////////////////////////////////////////////////////////////////////////
@@ -1248,7 +1251,7 @@ TEST_CASE("An lvalue noncopyable and nonmovable functor can be used to create "
1248
1251
" a scope_guard, because it binds to an lvalue reference" )
1249
1252
{
1250
1253
nocopy_nomove ncnm{};
1251
- make_scope_guard (ncnm);
1254
+ std::ignore = make_scope_guard (ncnm);
1252
1255
}
1253
1256
1254
1257
// //////////////////////////////////////////////////////////////////////////////
@@ -1273,7 +1276,7 @@ TEST_CASE("A const lvalue noncopyable and nonmovable functor can be used to "
1273
1276
" binds to a const lvalue reference" )
1274
1277
{
1275
1278
const nocopy_nomove ncnm{};
1276
- make_scope_guard (ncnm);
1279
+ std::ignore = make_scope_guard (ncnm);
1277
1280
}
1278
1281
1279
1282
// //////////////////////////////////////////////////////////////////////////////
@@ -1383,7 +1386,7 @@ namespace
1383
1386
TEST_CASE (" A lambda-wrapped regular method can be used to create a scope_guard" )
1384
1387
{
1385
1388
regular_method_holder h{};
1386
- make_scope_guard ([&h]() noexcept { h.regular_inc_method (); });
1389
+ std::ignore = make_scope_guard ([&h]() noexcept { h.regular_inc_method (); });
1387
1390
}
1388
1391
1389
1392
// //////////////////////////////////////////////////////////////////////////////
@@ -1423,7 +1426,8 @@ TEST_CASE("A dismissed lambda-wrapped-regular-method-based scope_guard does "
1423
1426
TEST_CASE (" A bound regular method can be used to create a scope_guard" )
1424
1427
{
1425
1428
regular_method_holder h{};
1426
- make_scope_guard (std::bind (®ular_method_holder::regular_inc_method, h));
1429
+ std::ignore = make_scope_guard (
1430
+ std::bind (®ular_method_holder::regular_inc_method, h));
1427
1431
}
1428
1432
1429
1433
// //////////////////////////////////////////////////////////////////////////////
@@ -1446,7 +1450,7 @@ TEST_CASE("A bound-regular-method-based scope_guard executes the method "
1446
1450
TEST_CASE (" A lambda-wrapped const method can be used to create a scope_guard" )
1447
1451
{
1448
1452
const const_method_holder h{};
1449
- make_scope_guard ([&h]() noexcept { h.const_inc_method (); });
1453
+ std::ignore = make_scope_guard ([&h]() noexcept { h.const_inc_method (); });
1450
1454
}
1451
1455
1452
1456
// //////////////////////////////////////////////////////////////////////////////
@@ -1469,7 +1473,8 @@ TEST_CASE("A lambda-wrapped-const-method-based scope_guard executes the "
1469
1473
TEST_CASE (" A bound const method can be used to create a scope_guard" )
1470
1474
{
1471
1475
const const_method_holder h{};
1472
- make_scope_guard (std::bind (&const_method_holder::const_inc_method, h));
1476
+ std::ignore =
1477
+ make_scope_guard (std::bind (&const_method_holder::const_inc_method, h));
1473
1478
}
1474
1479
1475
1480
// //////////////////////////////////////////////////////////////////////////////
@@ -1509,7 +1514,7 @@ TEST_CASE("A dismissed, bound-const-method-based scope_guard does not execute "
1509
1514
// //////////////////////////////////////////////////////////////////////////////
1510
1515
TEST_CASE (" A static method can be used to create a scope_guard" )
1511
1516
{
1512
- make_scope_guard (static_method_holder::static_inc_method);
1517
+ std::ignore = make_scope_guard (static_method_holder::static_inc_method);
1513
1518
}
1514
1519
1515
1520
// //////////////////////////////////////////////////////////////////////////////
@@ -1530,7 +1535,7 @@ TEST_CASE("A static-method-based scope_guard executes the static method "
1530
1535
TEST_CASE (" A lambda-wrapped virtual method can be used to create a scope_guard" )
1531
1536
{
1532
1537
virtual_method_holder h{};
1533
- make_scope_guard ([&h]() noexcept { h.virtual_inc_method (); });
1538
+ std::ignore = make_scope_guard ([&h]() noexcept { h.virtual_inc_method (); });
1534
1539
}
1535
1540
1536
1541
// //////////////////////////////////////////////////////////////////////////////
@@ -1640,14 +1645,14 @@ namespace
1640
1645
auto sfinae_tester_impl (T&& t, tag_prefered_overload&& /* ignored*/ )
1641
1646
-> decltype(make_scope_guard(std::forward<T>(t)), std::declval<void>())
1642
1647
{
1643
- make_scope_guard (std::forward<T>(t));
1648
+ std::ignore = make_scope_guard (std::forward<T>(t));
1644
1649
}
1645
1650
1646
1651
template <typename T>
1647
1652
void sfinae_tester_impl (T&& /* ignored*/ ,
1648
1653
... /* less specific, so 2nd choice */ )
1649
1654
{
1650
- make_scope_guard (inc);
1655
+ std::ignore = make_scope_guard (inc);
1651
1656
}
1652
1657
1653
1658
template <typename T>
0 commit comments