491
491
gmock_PerformImpl (\
492
492
GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
493
493
494
-
495
494
namespace testing {
496
495
497
-
498
496
// The ACTION*() macros trigger warning C4100 (unreferenced formal
499
497
// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
500
498
// the macro definition, as the warnings are generated when the macro
@@ -505,24 +503,52 @@ namespace testing {
505
503
# pragma warning(disable:4100)
506
504
#endif
507
505
508
- // Various overloads for InvokeArgument<N>().
509
- //
506
+ namespace internal {
507
+
508
+ // internal::InvokeArgument - a helper for InvokeArgument action.
509
+ // The basic overloads are provided here for generic functors.
510
+ // Overloads for other custom-callables are provided in the
511
+ // internal/custom/gmock-generated-actions.h header.
512
+ template <typename F, typename ... Args>
513
+ auto InvokeArgument (F f, Args... args) -> decltype(f(args...)) {
514
+ return f (args...);
515
+ }
516
+
517
+ template <std::size_t index, typename ... Params>
518
+ struct InvokeArgumentAction {
519
+ template <typename ... Args>
520
+ auto operator ()(Args&&... args) const -> decltype(internal::InvokeArgument(
521
+ std::get<index>(std::forward_as_tuple(std::forward<Args>(args)...)),
522
+ std::declval<const Params&>()...)) {
523
+ internal::FlatTuple<Args&&...> args_tuple (std::forward<Args>(args)...);
524
+ return params.Apply ([&](const Params&... unpacked_params) {
525
+ auto && callable = args_tuple.template Get <index >();
526
+ return internal::InvokeArgument (
527
+ std::forward<decltype (callable)>(callable), unpacked_params...);
528
+ });
529
+ }
530
+
531
+ internal::FlatTuple<Params...> params;
532
+ };
533
+
534
+ } // namespace internal
535
+
510
536
// The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
511
537
// (0-based) argument, which must be a k-ary callable, of the mock
512
538
// function, with arguments a1, a2, ..., a_k.
513
539
//
514
540
// Notes:
515
541
//
516
542
// 1. The arguments are passed by value by default. If you need to
517
- // pass an argument by reference, wrap it inside ByRef (). For
543
+ // pass an argument by reference, wrap it inside std::ref (). For
518
544
// example,
519
545
//
520
- // InvokeArgument<1>(5, string("Hello"), ByRef (foo))
546
+ // InvokeArgument<1>(5, string("Hello"), std::ref (foo))
521
547
//
522
548
// passes 5 and string("Hello") by value, and passes foo by
523
549
// reference.
524
550
//
525
- // 2. If the callable takes an argument by reference but ByRef () is
551
+ // 2. If the callable takes an argument by reference but std::ref () is
526
552
// not used, it will receive the reference to a copy of the value,
527
553
// instead of the original value. For example, when the 0-th
528
554
// argument of the mock function takes a const string&, the action
@@ -534,75 +560,11 @@ namespace testing {
534
560
// to the callable. This makes it easy for a user to define an
535
561
// InvokeArgument action from temporary values and have it performed
536
562
// later.
537
-
538
- ACTION_TEMPLATE (InvokeArgument,
539
- HAS_1_TEMPLATE_PARAMS (int , k),
540
- AND_0_VALUE_PARAMS ()) {
541
- return internal::InvokeArgument (::std::get<k>(args));
542
- }
543
-
544
- ACTION_TEMPLATE (InvokeArgument,
545
- HAS_1_TEMPLATE_PARAMS (int , k),
546
- AND_1_VALUE_PARAMS (p0)) {
547
- return internal::InvokeArgument (::std::get<k>(args), p0);
548
- }
549
-
550
- ACTION_TEMPLATE (InvokeArgument,
551
- HAS_1_TEMPLATE_PARAMS (int , k),
552
- AND_2_VALUE_PARAMS (p0, p1)) {
553
- return internal::InvokeArgument (::std::get<k>(args), p0, p1);
554
- }
555
-
556
- ACTION_TEMPLATE (InvokeArgument,
557
- HAS_1_TEMPLATE_PARAMS (int , k),
558
- AND_3_VALUE_PARAMS (p0, p1, p2)) {
559
- return internal::InvokeArgument (::std::get<k>(args), p0, p1, p2);
560
- }
561
-
562
- ACTION_TEMPLATE (InvokeArgument,
563
- HAS_1_TEMPLATE_PARAMS (int , k),
564
- AND_4_VALUE_PARAMS (p0, p1, p2, p3)) {
565
- return internal::InvokeArgument (::std::get<k>(args), p0, p1, p2, p3);
566
- }
567
-
568
- ACTION_TEMPLATE (InvokeArgument,
569
- HAS_1_TEMPLATE_PARAMS (int , k),
570
- AND_5_VALUE_PARAMS (p0, p1, p2, p3, p4)) {
571
- return internal::InvokeArgument (::std::get<k>(args), p0, p1, p2, p3, p4);
572
- }
573
-
574
- ACTION_TEMPLATE (InvokeArgument,
575
- HAS_1_TEMPLATE_PARAMS (int , k),
576
- AND_6_VALUE_PARAMS (p0, p1, p2, p3, p4, p5)) {
577
- return internal::InvokeArgument (::std::get<k>(args), p0, p1, p2, p3, p4, p5);
578
- }
579
-
580
- ACTION_TEMPLATE (InvokeArgument,
581
- HAS_1_TEMPLATE_PARAMS (int , k),
582
- AND_7_VALUE_PARAMS (p0, p1, p2, p3, p4, p5, p6)) {
583
- return internal::InvokeArgument (::std::get<k>(args), p0, p1, p2, p3, p4, p5,
584
- p6);
585
- }
586
-
587
- ACTION_TEMPLATE (InvokeArgument,
588
- HAS_1_TEMPLATE_PARAMS (int , k),
589
- AND_8_VALUE_PARAMS (p0, p1, p2, p3, p4, p5, p6, p7)) {
590
- return internal::InvokeArgument (::std::get<k>(args), p0, p1, p2, p3, p4, p5,
591
- p6, p7);
592
- }
593
-
594
- ACTION_TEMPLATE (InvokeArgument,
595
- HAS_1_TEMPLATE_PARAMS (int , k),
596
- AND_9_VALUE_PARAMS (p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
597
- return internal::InvokeArgument (::std::get<k>(args), p0, p1, p2, p3, p4, p5,
598
- p6, p7, p8);
599
- }
600
-
601
- ACTION_TEMPLATE (InvokeArgument,
602
- HAS_1_TEMPLATE_PARAMS (int , k),
603
- AND_10_VALUE_PARAMS (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
604
- return internal::InvokeArgument (::std::get<k>(args), p0, p1, p2, p3, p4, p5,
605
- p6, p7, p8, p9);
563
+ template <std::size_t index , typename ... Params>
564
+ internal::InvokeArgumentAction<index , typename std::decay<Params>::type...>
565
+ InvokeArgument (Params&&... params) {
566
+ return {internal::FlatTuple<typename std::decay<Params>::type...>(
567
+ std::forward<Params>(params)...)};
606
568
}
607
569
608
570
#ifdef _MSC_VER
0 commit comments