-
Notifications
You must be signed in to change notification settings - Fork 0
/
P049.Restrictions.cpp
83 lines (73 loc) · 1.2 KB
/
P049.Restrictions.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
void f()
{
std::cout << "void f()" << std::endl;
}
// function pointer as template parameter
template<void(*Func)()>
void f1()
{
Func();
}
class Foo
{
public:
Foo() : x(0) {}
void print()
{
std::cout << "void Foo::print()" << std::endl;
}
double x;
};
Foo foo;
// obejct pointer as template parameter
template<Foo* pFoo>
void f2()
{
pFoo->print();
}
// member function pointer as temlate parameter
template<void(Foo::*pnf)()>
void f3()
{
Foo foo;
(foo.*pnf)();
}
// data memeber pointer as template paramter
template<double Foo::*pData>
void f4()
{
Foo foo;
std::cout << foo.*pData << std::endl;
}
// lvalue reference to obejct as template parameter
template<Foo& rfoo>
void f5()
{
rfoo.print();
}
// lvalue reference to function as template parameter
template<void(&func)()>
void f6()
{
func();
}
// nullptr_t as template parameter
template<std::nullptr_t p>
void f7()
{
std::cout << "void f7()" << std::endl;
}
int main(int argc, char const *argv[])
{
f1<f>();
f2<&foo>();
f3<&Foo::print>();
f4<&Foo::x>();
f5<foo>();
f6<f>();
f7<nullptr>();
static Foo foo2;
f2<&foo2>();
return 0;
}