]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/accumulators/test/reference.cpp
1 // (C) Copyright Eric Niebler 2005.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/test/unit_test.hpp>
7 #include <boost/accumulators/accumulators.hpp>
8 #include <boost/accumulators/statistics/stats.hpp>
9 #include <boost/accumulators/statistics/mean.hpp>
11 using namespace boost
;
12 using namespace unit_test
;
13 using namespace accumulators
;
17 BOOST_PARAMETER_KEYWORD(tag
, int_ref
)
18 BOOST_PARAMETER_KEYWORD(tag
, sum_acc
)
21 ///////////////////////////////////////////////////////////////////////////////
27 accumulator_set
<double, stats
<tag::reference
<int, my::tag::int_ref
> > > acc(
30 int &ref1
= accumulators::reference
<int, my::tag::int_ref
>(acc
);
31 int &ref2
= accumulators::reference_tag
<my::tag::int_ref
>(acc
);
33 BOOST_CHECK_EQUAL(&i
, &ref1
);
34 BOOST_CHECK_EQUAL(&i
, &ref2
);
37 ///////////////////////////////////////////////////////////////////////////////
42 typedef accumulator_set
<int, stats
<tag::sum
> > sum_acc_type
;
43 sum_acc_type sum_acc
; // the sum accumulator
48 , tag::external
<tag::sum
, my::tag::sum_acc
> // make sum external
49 , tag::reference
<sum_acc_type
, my::tag::sum_acc
> // and hold a reference to it
51 > acc_with_ref(my::sum_acc
= sum_acc
); // initialize the reference sum
54 sum_acc(2); // sum is now 3 for both
56 BOOST_CHECK_EQUAL(sum(acc_with_ref
), sum(sum_acc
));
57 BOOST_CHECK_EQUAL(sum(acc_with_ref
), 3);
60 ///////////////////////////////////////////////////////////////////////////////
65 typedef accumulator_set
<int, stats
<tag::sum
> > sum_acc_type
;
66 sum_acc_type sum_acc
; // the sum accumulator
71 // make sum external and hold a reference to it
72 , tag::external
<tag::sum
, my::tag::sum_acc
, sum_acc_type
>
74 > acc_with_ref(my::sum_acc
= sum_acc
); // initialize the reference sum
77 sum_acc(2); // sum is now 3 for both
79 BOOST_CHECK_EQUAL(sum(acc_with_ref
), sum(sum_acc
));
80 BOOST_CHECK_EQUAL(sum(acc_with_ref
), 3);
83 ///////////////////////////////////////////////////////////////////////////////
84 // init_unit_test_suite
86 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
88 test_suite
*test
= BOOST_TEST_SUITE("reference_accumulator test");
90 test
->add(BOOST_TEST_CASE(&test_stat
));
91 test
->add(BOOST_TEST_CASE(&test_external
));
92 test
->add(BOOST_TEST_CASE(&test_external2
));