111
|
1 /* { dg-do compile } */
|
|
2 /* { dg-options "-O2" } */
|
131
|
3 // { dg-additional-options "-Wno-return-type" }
|
111
|
4 namespace sigc {
|
|
5 template <class T_type> struct type_trait {
|
|
6 typedef T_type& pass;
|
|
7 typedef const T_type& take;
|
|
8 typedef T_type* pointer;
|
|
9 };
|
|
10 template <class T_type> struct type_trait<T_type&> {
|
|
11 typedef T_type& pass;
|
|
12 };
|
|
13 template<> struct type_trait<void> {
|
|
14 typedef void pass;
|
|
15 };
|
|
16 template <class T_base, class T_derived> struct is_base_and_derived {
|
|
17 struct big {
|
|
18 char memory[64];
|
|
19 };
|
|
20 static big is_base_class_(...);
|
|
21 static char is_base_class_(typename type_trait<T_base>::pointer);
|
|
22 static const bool value = sizeof(is_base_class_(reinterpret_cast<typename type_trait<T_derived>::pointer>(0))) == sizeof(char);
|
|
23 };
|
|
24 struct nil;
|
|
25 struct functor_base {
|
|
26 };
|
|
27 template <class T_functor, bool I_derives_functor_base=is_base_and_derived<functor_base,T_functor>::value> struct functor_trait {
|
|
28 typedef typename T_functor::result_type result_type;
|
|
29 typedef T_functor functor_type;
|
|
30 };
|
|
31 struct adaptor_base : public functor_base {
|
|
32 };
|
|
33 template <class T_functor, class T_arg1=void,class T_arg2=void,class T_arg3=void,class T_arg4=void,class T_arg5=void,class T_arg6=void,class T_arg7=void, bool I_derives_adaptor_base=is_base_and_derived<adaptor_base,T_functor>::value> struct deduce_result_type {
|
|
34 typedef typename functor_trait<T_functor>::result_type type;
|
|
35 };
|
|
36 template <class T_functor> struct adaptor_functor
|
|
37 : public adaptor_base {
|
|
38 template <class T_arg1=void,class T_arg2=void,class T_arg3=void,class T_arg4=void,class T_arg5=void,class T_arg6=void,class T_arg7=void> struct deduce_result_type {
|
|
39 typedef typename sigc::deduce_result_type<T_functor, T_arg1,T_arg2,T_arg3,T_arg4,T_arg5,T_arg6,T_arg7>::type type;
|
|
40 };
|
|
41 typedef typename functor_trait<T_functor>::result_type result_type;
|
|
42 template <class T_arg1,class T_arg2> typename deduce_result_type<T_arg1,T_arg2>::type operator()(T_arg1 _A_arg1,T_arg2 _A_arg2) const {
|
|
43 return functor_(_A_arg1,_A_arg2);
|
|
44 }
|
|
45 explicit adaptor_functor(const T_functor& _A_functor) : functor_(_A_functor) {
|
|
46 }
|
|
47 mutable T_functor functor_;
|
|
48 };
|
|
49 template <class T_functor, bool I_isadaptor = is_base_and_derived<adaptor_base, T_functor>::value> struct adaptor_trait;
|
|
50 template <class T_functor> struct adaptor_trait<T_functor, true> {
|
|
51 typedef T_functor adaptor_type;
|
|
52 };
|
|
53 template <class T_functor> struct adaptor_trait<T_functor, false> {
|
|
54 typedef typename functor_trait<T_functor>::functor_type functor_type;
|
|
55 typedef adaptor_functor<functor_type> adaptor_type;
|
|
56 };
|
|
57 template <class T_functor> struct adapts
|
|
58 : public adaptor_base {
|
|
59 typedef typename adaptor_trait<T_functor>::adaptor_type adaptor_type;
|
|
60 explicit adapts(const T_functor& _A_functor) : functor_(_A_functor) {
|
|
61 }
|
|
62 mutable adaptor_type functor_;
|
|
63 };
|
|
64 template <class T_type> struct unwrap_reference {
|
|
65 typedef T_type type;
|
|
66 };
|
|
67 template <class T_type> class bound_argument {
|
|
68 public:
|
|
69 bound_argument(const T_type& _A_argument) : visited_(_A_argument) {
|
|
70 }
|
|
71 inline T_type& invoke() {
|
|
72 }
|
|
73 T_type visited_;
|
|
74 };
|
|
75 template <int I_location, class T_functor, class T_type1=nil,class T_type2=nil,class T_type3=nil,class T_type4=nil,class T_type5=nil,class T_type6=nil,class T_type7=nil> struct bind_functor;
|
|
76 template <class T_functor, class T_bound> struct bind_functor<0, T_functor, T_bound, nil,nil,nil,nil,nil,nil> : public adapts<T_functor> {
|
|
77 typedef typename adapts<T_functor>::adaptor_type adaptor_type;
|
|
78 template <class T_arg1=void,class T_arg2=void,class T_arg3=void,class T_arg4=void,class T_arg5=void,class T_arg6=void,class T_arg7=void> struct deduce_result_type {
|
|
79 typedef typename adaptor_type::template deduce_result_type<typename type_trait<typename unwrap_reference<T_bound>::type>::pass, typename type_trait<T_arg1>::pass, typename type_trait<T_arg2>::pass, typename type_trait<T_arg3>::pass, typename type_trait<T_arg4>::pass, typename type_trait<T_arg5>::pass, typename type_trait<T_arg6>::pass>::type type;
|
|
80 };
|
|
81 typedef typename adaptor_type::result_type result_type;
|
|
82 result_type operator()() {
|
|
83 return this->functor_.template operator()<typename type_trait<typename unwrap_reference<T_bound>::type>::pass> (bound_.invoke());
|
|
84 }
|
|
85 template <class T_arg1> typename deduce_result_type<T_arg1>::type operator()(T_arg1 _A_arg1) {
|
|
86 return this->functor_.template operator()<typename type_trait<typename unwrap_reference<T_bound>::type>::pass, typename type_trait<T_arg1>::pass> (bound_.invoke(), _A_arg1);
|
|
87 }
|
|
88 bind_functor(typename type_trait<T_functor>::take _A_func, typename type_trait<T_bound>::take _A_bound) : adapts<T_functor>(_A_func), bound_(_A_bound) {
|
|
89 }
|
|
90 bound_argument<T_bound> bound_;
|
|
91 };
|
|
92 template <int I_location, class T_bound1, class T_functor> inline bind_functor<I_location, T_functor, T_bound1> bind(const T_functor& _A_func, T_bound1 _A_b1) {
|
|
93 return bind_functor<I_location, T_functor, T_bound1>(_A_func, _A_b1);
|
|
94 };
|
|
95 }
|
|
96 struct foo {
|
|
97 typedef int result_type;
|
|
98 int operator()(int i, int j);
|
|
99 };
|
|
100 int main() {
|
|
101 sigc::bind<0>(sigc::bind<0>(foo(),7),8)();
|
|
102 }
|