fix doc example typo
[boost.git] / boost / accumulators / statistics / tail_variate.hpp
blobee49fd5f7145aaec19011ef1edc6ac305d21296f
1 ///////////////////////////////////////////////////////////////////////////////
2 // tail_variate.hpp
3 //
4 // Copyright 2005 Eric Niebler, Michael Gauckler. 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_STAT_STATISTICS_TAIL_VARIATE_HPP_EAN_28_10_2005
9 #define BOOST_STAT_STATISTICS_TAIL_VARIATE_HPP_EAN_28_10_2005
11 #include <boost/range.hpp>
12 #include <boost/mpl/always.hpp>
13 #include <boost/mpl/placeholders.hpp>
14 #include <boost/iterator/reverse_iterator.hpp>
15 #include <boost/iterator/permutation_iterator.hpp>
16 #include <boost/accumulators/framework/accumulator_base.hpp>
17 #include <boost/accumulators/framework/extractor.hpp>
18 #include <boost/accumulators/framework/depends_on.hpp>
19 #include <boost/accumulators/statistics_fwd.hpp>
20 #include <boost/accumulators/statistics/tail.hpp>
22 namespace boost { namespace accumulators
25 namespace impl
27 ///////////////////////////////////////////////////////////////////////////////
28 // tail_variate_impl
29 template<typename VariateType, typename VariateTag, typename LeftRight>
30 struct tail_variate_impl
31 : accumulator_base
33 // for boost::result_of
34 typedef
35 typename detail::tail_range<
36 typename std::vector<VariateType>::const_iterator
37 , std::vector<std::size_t>::iterator
38 >::type
39 result_type;
41 template<typename Args>
42 tail_variate_impl(Args const &args)
43 : variates(args[tag::tail<LeftRight>::cache_size], args[parameter::keyword<VariateTag>::get() | VariateType()])
47 template<typename Args>
48 void assign(Args const &args, std::size_t index)
50 this->variates[index] = args[parameter::keyword<VariateTag>::get()];
53 template<typename Args>
54 result_type result(Args const &args) const
56 // getting the order result causes the indices vector to be sorted.
57 extractor<tag::tail<LeftRight> > const some_tail = {};
58 return this->do_result(some_tail(args));
61 private:
62 template<typename TailRng>
63 result_type do_result(TailRng const &rng) const
65 return detail::make_tail_range(
66 this->variates.begin()
67 , rng.end().base().base() // the index iterator
68 , rng.begin().base().base() // (begin and end reversed because these are reverse iterators)
72 std::vector<VariateType> variates;
75 } // namespace impl
77 ///////////////////////////////////////////////////////////////////////////////
78 // tag::tail_variate<>
80 namespace tag
82 template<typename VariateType, typename VariateTag, typename LeftRight>
83 struct tail_variate
84 : depends_on<tail<LeftRight> >
86 /// INTERNAL ONLY
87 ///
88 typedef mpl::always<accumulators::impl::tail_variate_impl<VariateType, VariateTag, LeftRight> > impl;
91 struct abstract_tail_variate
92 : depends_on<>
96 template<typename LeftRight>
97 struct tail_weights
98 : depends_on<tail<LeftRight> >
100 /// INTERNAL ONLY
102 typedef accumulators::impl::tail_variate_impl<mpl::_2, tag::weight, LeftRight> impl;
105 struct abstract_tail_weights
106 : depends_on<>
111 ///////////////////////////////////////////////////////////////////////////////
112 // extract::tail_variate
113 // extract::tail_weights
115 namespace extract
117 extractor<tag::abstract_tail_variate> const tail_variate = {};
118 extractor<tag::abstract_tail_weights> const tail_weights = {};
121 using extract::tail_variate;
122 using extract::tail_weights;
124 template<typename VariateType, typename VariateTag, typename LeftRight>
125 struct feature_of<tag::tail_variate<VariateType, VariateTag, LeftRight> >
126 : feature_of<tag::abstract_tail_variate>
130 template<typename LeftRight>
131 struct feature_of<tag::tail_weights<LeftRight> >
133 typedef tag::abstract_tail_weights type;
136 }} // namespace boost::accumulators
138 #endif