/
when_vararg.cpp
91 lines (77 loc) · 2.13 KB
/
when_vararg.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
84
85
86
87
88
89
90
91
//#include<boost/proto/proto.hpp>
#include <iostream>
#include<boost/proto/proto.hpp>
#include<boost/proto/transform/when_vararg.hpp>
namespace proto = boost::proto;
struct foo
: proto::callable
{
typedef void result_type;
void operator()() const
{
std::cout << "nullary\n\n";
}
template <typename A0>
void operator()(A0 const& a0) const
{
std::cout << "unary:\n";
std::cout << typeid(A0).name() << "\n\n";
}
template <typename A0, typename A1>
void operator()(A0 const& a0, A1 const& a1) const
{
std::cout << "binary:\n";
std::cout << typeid(A0).name() << "\n";
std::cout << typeid(A1).name() << "\n\n";
}
template <typename A0, typename A1, typename A2>
void operator()(A0 const& a0, A1 const& a1, A2 const& a2) const
{
std::cout << "ternary:\n";
std::cout << typeid(A0).name() << "\n";
std::cout << typeid(A1).name() << "\n";
std::cout << typeid(A2).name() << "\n\n";
}
template <typename A0, typename A1, typename A2, typename A3>
void operator()(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3) const
{
std::cout << "4nary:\n";
std::cout << typeid(A0).name() << "\n";
std::cout << typeid(A1).name() << "\n";
std::cout << typeid(A2).name() << "\n\n";
std::cout << typeid(A3).name() << "\n\n";
}
};
struct test
: proto::when<
proto::function<proto::vararg<proto::_> >
, foo(proto::vararg<proto::_>)
>
{};
struct test2
: proto::when<
proto::function<proto::vararg<proto::_> >
, foo(proto::vararg<proto::_>, proto::_state)
>
{};
typedef proto::terminal<int>::type const i_t;
typedef proto::function<i_t>::type const f1_t;
typedef proto::function<i_t, i_t>::type const f2_t;
typedef proto::function<i_t, i_t, i_t>::type const f3_t;
int main()
{
f1_t f1 = {};
f2_t f2 = {};
f3_t f3 = {};
i_t i = {};
test()(f1);
test2()(f1, 5);
test()(f2);
test2()(f2, 5);
test()(f3);
test2()(f3, 5);
test()(i());
test2()(i(), 5);
test()(i);
//test2()(i, 5);
}