]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/signals/test/trackable_test.cpp
1 // Boost.Signals library
3 // Copyright Douglas Gregor 2001-2006. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // For more information, see http://www.boost.org
10 #include <boost/test/minimal.hpp>
11 #include <boost/signal.hpp>
12 #include <boost/bind.hpp>
14 struct short_lived
: public boost::BOOST_SIGNALS_NAMESPACE::trackable
{
19 template<typename T
> int operator()(const T
*, int i
) { return i
; }
23 struct max_or_default
{
24 typedef T result_type
;
26 template<typename InputIterator
>
27 T
operator()(InputIterator first
, InputIterator last
) const
33 for (; first
!= last
; ++first
)
34 max
= (*first
> max
)? *first
: max
;
40 int test_main(int, char*[])
42 typedef boost::signal1
<int, int, max_or_default
<int> > sig_type
;
45 // Test auto-disconnection
46 BOOST_CHECK(s1(5) == 0);
49 s1
.connect(boost::bind
<int>(swallow(), &shorty
, _1
));
50 BOOST_CHECK(s1(5) == 5);
52 BOOST_CHECK(s1(5) == 0);
54 // Test auto-disconnection of slot before signal connection
56 short_lived
* shorty
= new short_lived();
58 sig_type::slot_type
slot(boost::bind
<int>(swallow(), shorty
, _1
));
61 BOOST_CHECK(s1(5) == 0);