1 ///////////////////////////////////////////////////////////////////////////////
2 // external_accumulator.hpp
4 // Copyright 2005 Eric Niebler. 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)
8 #ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_EXTERNAL_ACCUMULATOR_HPP_EAN_01_12_2005
9 #define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_EXTERNAL_ACCUMULATOR_HPP_EAN_01_12_2005
11 #include <boost/mpl/placeholders.hpp>
12 #include <boost/parameter/keyword.hpp>
13 #include <boost/accumulators/framework/extractor.hpp>
14 #include <boost/accumulators/framework/depends_on.hpp> // for feature_tag
15 #include <boost/accumulators/framework/accumulator_base.hpp>
16 #include <boost/accumulators/framework/accumulators/reference_accumulator.hpp>
18 namespace boost { namespace accumulators { namespace impl
21 //////////////////////////////////////////////////////////////////////////
25 template<typename Accumulator, typename Tag>
29 typedef typename Accumulator::result_type result_type;
30 typedef typename detail::feature_tag<Accumulator>::type feature_tag;
32 external_impl(dont_care) {}
34 template<typename Args>
35 result_type result(Args const &args) const
37 return this->extract_(args, args[parameter::keyword<Tag>::instance | 0]);
42 template<typename Args>
43 static result_type extract_(Args const &args, int)
45 // No named parameter passed to the extractor. Maybe the external
46 // feature is held by reference<>.
47 extractor<feature_tag> extract;
48 return extract(accumulators::reference_tag<Tag>(args));
51 template<typename Args, typename AccumulatorSet>
52 static result_type extract_(Args const &, AccumulatorSet const &acc)
54 // OK, a named parameter for this external feature was passed to the
55 // extractor, so use that.
56 extractor<feature_tag> extract;
65 //////////////////////////////////////////////////////////////////////////
67 template<typename Feature, typename Tag, typename AccumulatorSet>
69 : depends_on<reference<AccumulatorSet, Tag> >
72 accumulators::impl::external_impl<
73 detail::to_accumulator<Feature, mpl::_1, mpl::_2>
79 template<typename Feature, typename Tag>
80 struct external<Feature, Tag, void>
84 accumulators::impl::external_impl<
85 detail::to_accumulator<Feature, mpl::_1, mpl::_2>
92 // for the purposes of feature-based dependency resolution,
93 // external_accumulator<Feature, Tag> provides the same feature as Feature
94 template<typename Feature, typename Tag, typename AccumulatorSet>
95 struct feature_of<tag::external<Feature, Tag, AccumulatorSet> >
100 // Note: Usually, the extractor is pulled into the accumulators namespace with
101 // a using directive, not the tag. But the external<> feature doesn't have an
102 // extractor, so we can put the external tag in the accumulators namespace
103 // without fear of a name conflict.
106 }} // namespace boost::accumulators