-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_invocation_time.cpp
More file actions
33 lines (26 loc) · 922 Bytes
/
function_invocation_time.cpp
File metadata and controls
33 lines (26 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <vector>
class Widget {};
void f(Widget &¶m) {} // rvalue reference
Widget &&var1 = Widget(); // rvalue reference
auto &&var2 = var1; // universal reference
template<typename T> void f2(std::vector<T> &¶m) {} // rvalue reference
template<typename T> void f3(T &¶m) {} // universal reference
template<typename T> void f4(const T &¶m) {} // param is an rvalue reference
auto function_invocation_time = [](auto &&func, auto &&... params) {
// start timer
std::forward<decltype(func)>(func)(
std::forward<decltype(params)>(params)...);
// stop timer and record elapsed time
};
int main() {
Widget w;
// lvalue passed to f3; param's type is Widget& (i.e., an lvalue reference)
f3(w);
// rvalue passed to f3; param's type is Widget&& (i.e., an rvalue reference)
f3(std::move(w));
std::vector<int> v;
// f2(v); // error
int i = 0;
// f4(i); // error
return 0;
}