1 // Boost.Signals library
3 // Copyright (C) 2001 Doug Gregor (gregod@cs.rpi.edu)
5 // Permission to copy, use, sell and distribute this software is granted
6 // provided this copyright notice appears in all copies.
7 // Permission to modify the code and to distribute modified code is granted
8 // provided this copyright notice appears in all copies, and a notice
9 // that the code was modified is included with the copyright notice.
11 // This software is provided "as is" without express or implied warranty,
12 // and with no claim as to its suitability for any purpose.
14 // For more information, see http://www.boost.org
16 #ifndef BOOST_SIGNALS_COMMON_HEADER
17 #define BOOST_SIGNALS_COMMON_HEADER
19 #include <boost/type_traits/conversion_traits.hpp>
20 #include <boost/ref.hpp>
25 // The unusable class is a placeholder for unused function arguments
26 // It is also completely unusable except that it constructable from
27 // anything. This helps compilers without partial specialization
28 // handle slots returning void.
33 // Determine the result type of a slot call
35 struct slot_result_type {
40 struct slot_result_type<void> {
41 typedef unusable type;
44 // Determine if the given type T is a signal
49 BOOST_STATIC_CONSTANT(bool,
50 value = (is_convertible<T*, signal_base*>::value));
54 * The IF implementation is temporary code. When a Boost metaprogramming
55 * library is introduced, Boost.Signals will use it instead.
60 template<typename Then, typename Else>
69 template<typename Then, typename Else>
76 template<bool Condition>
79 typedef SelectThen type;
83 struct Selector<false>
85 typedef SelectElse type;
87 } // end namespace intimate
89 template<bool Condition, typename Then, typename Else>
92 typedef typename intimate::Selector<Condition>::type select;
93 typedef typename select::template Result<Then,Else>::type type;
96 // Determine if the incoming argument is a reference_wrapper
97 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
101 BOOST_STATIC_CONSTANT(bool, value = false);
105 struct is_ref<reference_wrapper<T> >
107 BOOST_STATIC_CONSTANT(bool, value = true);
109 #else // no partial specialization
110 typedef char yes_type;
111 typedef double no_type;
113 no_type is_ref_tester(...);
116 yes_type is_ref_tester(reference_wrapper<T>*);
122 BOOST_STATIC_CONSTANT(bool,
123 value = (sizeof(is_ref_tester(t)) == sizeof(yes_type)));
125 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
127 // A slot can be a signal, a reference to a function object, or a
129 struct signal_tag {};
130 struct reference_tag {};
133 // Classify the given slot as a signal, a reference-to-slot, or a
137 typedef typename IF<(is_signal<S>::value),
139 value_tag>::type signal_or_value;
142 typedef typename IF<(is_ref<S>::value),
144 signal_or_value>::type type;
147 // Forward declaration needed in lots of places
148 class signal_base_impl;
149 class bound_objects_visitor;
151 } // end namespace detail
152 } // end namespace signals
153 } // end namespace boost
155 #endif // BOOST_SIGNALS_COMMON_HEADER