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 #ifndef BOOST_SIGNALS_NAMESPACE
20 # define BOOST_SIGNALS_NAMESPACE signals
23 #include <boost/type_traits/conversion_traits.hpp>
24 #include <boost/ref.hpp>
27 namespace BOOST_SIGNALS_NAMESPACE {
29 // The unusable class is a placeholder for unused function arguments
30 // It is also completely unusable except that it constructable from
31 // anything. This helps compilers without partial specialization
32 // handle slots returning void.
37 // Determine the result type of a slot call
39 struct slot_result_type {
44 struct slot_result_type<void> {
45 typedef unusable type;
48 // Determine if the given type T is a signal
53 BOOST_STATIC_CONSTANT(bool,
54 value = (is_convertible<T*, signal_base*>::value));
58 * The IF implementation is temporary code. When a Boost metaprogramming
59 * library is introduced, Boost.Signals will use it instead.
64 template<typename Then, typename Else>
73 template<typename Then, typename Else>
80 template<bool Condition>
83 typedef SelectThen type;
87 struct Selector<false>
89 typedef SelectElse type;
91 } // end namespace intimate
93 template<bool Condition, typename Then, typename Else>
96 typedef typename intimate::Selector<Condition>::type select;
97 typedef typename select::template Result<Then,Else>::type type;
100 // Determine if the incoming argument is a reference_wrapper
101 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
105 BOOST_STATIC_CONSTANT(bool, value = false);
109 struct is_ref<reference_wrapper<T> >
111 BOOST_STATIC_CONSTANT(bool, value = true);
113 #else // no partial specialization
114 typedef char yes_type;
115 typedef double no_type;
117 no_type is_ref_tester(...);
120 yes_type is_ref_tester(reference_wrapper<T>*);
126 BOOST_STATIC_CONSTANT(bool,
127 value = (sizeof(is_ref_tester(t)) == sizeof(yes_type)));
129 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
131 // A slot can be a signal, a reference to a function object, or a
133 struct signal_tag {};
134 struct reference_tag {};
137 // Classify the given slot as a signal, a reference-to-slot, or a
141 typedef typename IF<(is_signal<S>::value),
143 value_tag>::type signal_or_value;
146 typedef typename IF<(is_ref<S>::value),
148 signal_or_value>::type type;
151 // Forward declaration needed in lots of places
152 class signal_base_impl;
153 class bound_objects_visitor;
155 } // end namespace detail
156 } // end namespace BOOST_SIGNALS_NAMESPACE
157 } // end namespace boost
159 #endif // BOOST_SIGNALS_COMMON_HEADER