fix doc example typo
[boost.git] / boost / signals2 / slot.hpp
blobf44442f801bfb82d6ab786d1d0877f54ac2ee90e
1 // Boost.Signals2 library
3 // Copyright Frank Mori Hess 2007-2008.
4 // Copyright Timmo Stange 2007.
5 // Copyright Douglas Gregor 2001-2004. Use, modification and
6 // distribution is subject to the Boost Software License, Version
7 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 // For more information, see http://www.boost.org
12 #ifndef BOOST_SIGNALS2_SLOT_HPP
13 #define BOOST_SIGNALS2_SLOT_HPP
15 #include <boost/bind.hpp>
16 #include <boost/function.hpp>
17 #include <boost/preprocessor/repetition.hpp>
18 #include <boost/ref.hpp>
19 #include <boost/signals2/detail/signals_common.hpp>
20 #include <boost/signals2/detail/signals_common_macros.hpp>
21 #include <boost/signals2/detail/tracked_objects_visitor.hpp>
22 #include <boost/signals2/slot_base.hpp>
23 #include <boost/type_traits.hpp>
24 #include <boost/visit_each.hpp>
25 #include <boost/weak_ptr.hpp>
28 #ifndef BOOST_SIGNALS2_SLOT_MAX_BINDING_ARGS
29 #define BOOST_SIGNALS2_SLOT_MAX_BINDING_ARGS 10
30 #endif
31 // const ArgTypeN & argN
32 #define BOOST_SIGNALS2_SLOT_BINDING_ARG_DECL(z, n, data) \
33 const BOOST_PP_CAT(ArgType, n) & BOOST_PP_CAT(arg, n)
35 namespace boost
37 namespace signals2
39 namespace detail
41 // Get the slot so that it can be copied
42 template<typename F>
43 typename F::weak_signal_type
44 get_invocable_slot(const F &signal, signal_tag)
45 { return typename F::weak_signal_type(signal); }
47 template<typename F>
48 const F&
49 get_invocable_slot(const F& f, reference_tag)
50 { return f; }
52 template<typename F>
53 const F&
54 get_invocable_slot(const F& f, value_tag)
55 { return f; }
57 // Determines the type of the slot - is it a signal, a reference to a
58 // slot or just a normal slot.
59 template<typename F>
60 typename get_slot_tag<F>::type
61 tag_type(const F&)
63 typedef typename get_slot_tag<F>::type
64 the_tag_type;
65 the_tag_type tag = the_tag_type();
66 return tag;
70 } // end namespace boost
72 #define BOOST_PP_ITERATION_LIMITS (0, BOOST_PP_INC(BOOST_SIGNALS2_MAX_ARGS))
73 #define BOOST_PP_FILENAME_1 <boost/signals2/detail/slot_template.hpp>
74 #include BOOST_PP_ITERATE()
76 namespace boost
78 namespace signals2
80 template<typename Signature,
81 typename SlotFunction = boost::function<Signature> >
82 class slot: public detail::slotN<function_traits<Signature>::arity,
83 Signature, SlotFunction>::type
85 private:
86 typedef typename detail::slotN<boost::function_traits<Signature>::arity,
87 Signature, SlotFunction>::type base_type;
88 public:
89 template<typename F>
90 slot(const F& f): base_type(f)
92 // bind syntactic sugar
93 // template<typename F, typename ArgType0, typename ArgType1, ..., typename ArgTypen-1> slot(...
94 #define BOOST_SIGNALS2_SLOT_BINDING_CONSTRUCTOR(z, n, data) \
95 template<typename F, BOOST_PP_ENUM_PARAMS(n, typename ArgType)> \
96 slot(const F &f, BOOST_PP_ENUM(n, BOOST_SIGNALS2_SLOT_BINDING_ARG_DECL, ~)): \
97 base_type(f, BOOST_PP_ENUM_PARAMS(n, arg)) \
99 BOOST_PP_REPEAT_FROM_TO(1, BOOST_SIGNALS2_SLOT_MAX_BINDING_ARGS, BOOST_SIGNALS2_SLOT_BINDING_CONSTRUCTOR, ~)
100 #undef BOOST_SIGNALS2_SLOT_BINDING_CONSTRUCTOR
102 } // namespace signals2
105 #endif // BOOST_SIGNALS2_SLOT_HPP