1 ///////////////////////////////////////////////////////////////////////////////
2 // value_accumulator.hpp
3 //
4 //  Copyright 2005 Eric Niebler, Daniel Egloff. Distributed under the Boost
5 //  Software License, Version 1.0. (See accompanying file
6 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 
8 #ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_VALUE_ACCUMULATOR_HPP_EAN_03_23_2006
9 #define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_VALUE_ACCUMULATOR_HPP_EAN_03_23_2006
10 
11 #include <boost/mpl/always.hpp>
12 #include <boost/parameter/keyword.hpp>
13 #include <boost/accumulators/framework/depends_on.hpp> // for feature_tag
14 #include <boost/accumulators/framework/accumulator_base.hpp>
15 #include <boost/accumulators/framework/extractor.hpp>
16 
17 namespace boost { namespace accumulators
18 {
19 
20 namespace impl
21 {
22 
23     //////////////////////////////////////////////////////////////////////////
24     // value_accumulator_impl
25     template<typename ValueType, typename Tag>
26     struct value_accumulator_impl
27       : accumulator_base
28     {
29         typedef ValueType result_type;
30 
31         template<typename Args>
value_accumulator_implboost::accumulators::impl::value_accumulator_impl32         value_accumulator_impl(Args const &args)
33           : val(args[parameter::keyword<Tag>::get()])
34         {
35         }
36 
resultboost::accumulators::impl::value_accumulator_impl37         result_type result(dont_care) const
38         {
39             return this->val;
40         }
41 
42     private:
43         ValueType val;
44     };
45 
46 } // namespace impl
47 
48 namespace tag
49 {
50     //////////////////////////////////////////////////////////////////////////
51     // value_tag
52     template<typename Tag>
53     struct value_tag
54     {
55     };
56 
57     //////////////////////////////////////////////////////////////////////////
58     // value
59     template<typename ValueType, typename Tag>
60     struct value
61       : depends_on<>
62     {
63         /// INTERNAL ONLY
64         ///
65         typedef mpl::always<accumulators::impl::value_accumulator_impl<ValueType, Tag> > impl;
66     };
67 }
68 
69 namespace extract
70 {
71     BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, value, (typename)(typename))
72     BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, value_tag, (typename))
73 }
74 
75 using extract::value;
76 using extract::value_tag;
77 
78 // Map all value<V,T> features to value_tag<T> so
79 // that values can be extracted using value_tag<T>
80 // without specifying the value type.
81 template<typename ValueType, typename Tag>
82 struct feature_of<tag::value<ValueType, Tag> >
83   : feature_of<tag::value_tag<Tag> >
84 {
85 };
86 
87 }} // namespace boost::accumulators
88 
89 #endif
90