2 /* { dg-options "-fstrict-aliasing" } */
4 extern "C" void abort (void);
6 template <class T_type>
10 typedef const T_type& take;
11 typedef T_type* pointer;
13 template <class T_base, class T_derived>
14 struct is_base_and_derived
19 static big is_base_class_(...);
20 static char is_base_class_(typename type_trait<T_base>::pointer);
21 static const bool value =
22 sizeof(is_base_class_(reinterpret_cast<typename type_trait<T_derived>::pointer>(0))) ==
26 struct functor_base {};
27 template <class T_functor, bool I_derives_functor_base=is_base_and_derived<functor_base,T_functor>::value>
31 template <class T_functor>
32 struct functor_trait<T_functor,true>
34 typedef typename T_functor::result_type result_type;
35 typedef T_functor functor_type;
37 template <class T_arg1, class T_return>
38 class pointer_functor1 : public functor_base
40 typedef T_return (*function_type)(T_arg1);
41 function_type func_ptr_;
43 typedef T_return result_type;
44 explicit pointer_functor1(function_type _A_func): func_ptr_(_A_func) {}
45 T_return operator()(typename type_trait<T_arg1>::take _A_a1) const
46 { return func_ptr_(_A_a1); }
48 template <class T_arg1, class T_return>
49 inline pointer_functor1<T_arg1, T_return>
50 ptr_fun1(T_return (*_A_func)(T_arg1))
51 { return pointer_functor1<T_arg1, T_return>(_A_func); }
52 struct adaptor_base : public functor_base {};
53 template <class T_functor,
55 bool I_derives_adaptor_base=is_base_and_derived<adaptor_base,T_functor>::value>
56 struct deduce_result_type
57 { typedef typename functor_trait<T_functor>::result_type type; };
58 template <class T_functor>
59 struct adaptor_functor : public adaptor_base
61 template <class T_arg1=void>
62 struct deduce_result_type
63 { typedef typename sigc::deduce_result_type<T_functor, T_arg1>::type type; };
64 typedef typename functor_trait<T_functor>::result_type result_type;
67 template <class T_arg1>
68 typename deduce_result_type<T_arg1>::type
69 operator()(T_arg1 _A_arg1) const
70 { return functor_(_A_arg1); }
71 explicit adaptor_functor(const T_functor& _A_functor)
72 : functor_(_A_functor)
74 mutable T_functor functor_;
76 template <class T_functor>
77 typename adaptor_functor<T_functor>::result_type
78 adaptor_functor<T_functor>::operator()() const
79 { return functor_(); }
80 template <class T_functor, bool I_isadaptor = is_base_and_derived<adaptor_base, T_functor>::value> struct adaptor_trait;
81 template <class T_functor>
82 struct adaptor_trait<T_functor, true>
84 typedef T_functor adaptor_type;
86 template <class T_functor>
87 struct adaptor_trait<T_functor, false>
89 typedef typename functor_trait<T_functor>::functor_type functor_type;
90 typedef adaptor_functor<functor_type> adaptor_type;
92 template <class T_functor>
93 struct adapts : public adaptor_base
95 typedef typename adaptor_trait<T_functor>::adaptor_type adaptor_type;
96 explicit adapts(const T_functor& _A_functor)
97 : functor_(_A_functor)
99 mutable adaptor_type functor_;
101 template <class T_type>
102 struct reference_wrapper
105 template <class T_type>
106 struct unwrap_reference
110 template <class T_type>
114 bound_argument(const T_type& _A_argument)
115 : visited_(_A_argument)
117 inline T_type& invoke()
121 template <class T_wrapped>
122 class bound_argument< reference_wrapper<T_wrapped> >
125 template <int I_location, class T_functor, class T_type1=nil>
127 template <class T_functor, class T_type1>
128 struct bind_functor<-1, T_functor, T_type1> : public adapts<T_functor>
130 typedef typename adapts<T_functor>::adaptor_type adaptor_type;
131 typedef typename adaptor_type::result_type result_type;
135 return this->functor_.template operator()<typename type_trait<typename unwrap_reference<T_type1>::type>::pass> (bound1_.invoke());
137 bind_functor(typename type_trait<T_functor>::take _A_func, typename type_trait<T_type1>::take _A_bound1)
138 : adapts<T_functor>(_A_func), bound1_(_A_bound1)
140 bound_argument<T_type1> bound1_;
142 template <class T_type1, class T_functor>
143 inline bind_functor<-1, T_functor,
145 bind(const T_functor& _A_func, T_type1 _A_b1)
146 { return bind_functor<-1, T_functor,
152 typedef void* (*hook)(slot_rep *);
158 class slot_base : public functor_base
161 typedef internal::slot_rep rep_type;
162 explicit slot_base(rep_type* rep)
166 mutable rep_type *rep_;
169 template <class T_functor>
170 struct typed_slot_rep : public slot_rep
172 typedef typename adaptor_trait<T_functor>::adaptor_type adaptor_type;
173 adaptor_type functor_;
174 inline typed_slot_rep(const T_functor& functor)
179 template<class T_functor>
182 static void *call_it(slot_rep* rep)
184 typedef typed_slot_rep<T_functor> typed_slot;
185 typed_slot *typed_rep = static_cast<typed_slot*>(rep);
186 return (typed_rep->functor_)();
188 static hook address()
195 class slot0 : public slot_base
198 typedef void * (*call_type)(rep_type*);
199 inline void *operator()() const
201 return slot_base::rep_->call_ (slot_base::rep_);
203 template <class T_functor>
204 slot0(const T_functor& _A_func)
205 : slot_base(new internal::typed_slot_rep<T_functor>(_A_func))
207 slot_base::rep_->call_ = internal::slot_call0<T_functor>::address();
213 static void *foo (void *p) { return p; }
214 typedef sigc::slot0 C;
219 return sigc::bind (sigc::ptr_fun1 (&A::foo), (void*)0);