File tree Expand file tree Collapse file tree 2 files changed +14
-10
lines changed
Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,12 @@ namespace functions {
44
55#include < iostream>
66
7- int function (int x) { return x; }
8-
9- using FunctionPtr = decltype (&function);
10-
11- FunctionPtr intermediary () { return function; }
7+ std::function<void (int & p)> do_it (int & param) {
8+ param++;
9+ static int counter = 1 ;
10+ std::cout << " do it #" << counter << " : param = " << param << std::endl;
11+ counter++;
12+ return [](int & p) { do_it (p); };
13+ }
1214
1315} // namespace functions
Original file line number Diff line number Diff line change 11#include " gtest/gtest.h"
22#include " self-pointed-function.hpp"
33
4- using functions::FunctionPtr;
5- using functions::intermediary;
4+ using functions::do_it;
65
76TEST (SelfPointedFunction, Call) {
8- FunctionPtr f = intermediary ();
9- constexpr int x = 10 ;
10- EXPECT_EQ (f (x), x);
7+ constexpr int initial = 42 ;
8+ int var = initial; // NOLINT
9+ auto do_it_again = do_it (var);
10+ EXPECT_EQ (var, initial + 1 );
11+ do_it_again (var);
12+ EXPECT_EQ (var, initial + 2 );
1113}
You can’t perform that action at this time.
0 commit comments