Ticket #2833: example_temp_accu.cpp

File example_temp_accu.cpp, 1.9 KB (added by anonymous, 14 years ago)
Line 
1#include <boost/type_traits.hpp>
2#include <boost/assert.hpp>
3#include <boost/mpl/vector.hpp>
4#include <boost/mpl/equal_to.hpp>
5#include <boost/mpl/assert.hpp>
6#include <boost/mpl/transform.hpp>
7#include <boost/shared_features/temp/accu_a.hpp>
8#include <boost/shared_features/temp/accu_b.hpp>
9#include <boost/accumulators/statistics/stats.hpp>
10#include <boost/accumulators/framework/depends_on.hpp>
11#include <boost/accumulators/framework/accumulator_set.hpp>
12#include <boost/accumulators/framework/extractor.hpp>
13#include <iostream>
14#include <libs/shared_features/src/example/temp_accu.h>
15
16
17void example_temp_accu(){
18
19 using namespace boost;
20 using namespace boost::accumulators;
21
22 typedef mpl::size_t<0> id0;
23 typedef mpl::size_t<1> id1;
24
25 typedef double value_type;
26 typedef tag::accu_a<id0> a_type;
27 typedef tag::accu_b<id1,id0> b_type;
28
29 typedef accumulator_set<
30 value_type,
31 stats<
32 b_type
33 >
34 > set_type;
35
36
37 typedef set_type::accumulators_mpl_vector::type wrapped_features;
38
39 typedef mpl::transform<
40 wrapped_features,
41 accumulators::detail::feature_tag<mpl::_1>
42 >::type features;
43
44 BOOST_STATIC_ASSERT((
45 mpl::equal_to<
46 mpl::size_t<2>,
47 mpl::size<features>::type
48 >::value
49 ));
50
51 typedef mpl::back<features>::type actual_back;
52
53 BOOST_STATIC_ASSERT((
54 is_same<b_type,actual_back>::value
55 ));
56
57
58 set_type set(
59 (
60 kwd<id0>::value = 0.9
61 )
62 ); //supposed to set b.x_ = a.x_;
63
64
65 std::cout << "a.x_=" << extract_result<a_type>(set) << std::endl;
66 std::cout << "b.x_=" << extract_result<b_type>(set) << std::endl;
67 set(0); // sets b.x_ = a.x_ again
68 std::cout << "b.x_=" << extract_result<b_type>(set) << std::endl;
69
70//Output:
71//a.x_=0.9
72//b.x_=0.1 // expects 0.9
73//b.x_=0.9
74
75
76}