/Src/Dependencies/Boost/boost/accumulators/statistics/tail_variate.hpp

http://hadesmem.googlecode.com/ · C++ Header · 141 lines · 99 code · 21 blank · 21 comment · 0 complexity · db6a2a5c85219432433c6597d90ac58c MD5 · raw file

  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)
  7. #ifndef BOOST_STAT_STATISTICS_TAIL_VARIATE_HPP_EAN_28_10_2005
  8. #define BOOST_STAT_STATISTICS_TAIL_VARIATE_HPP_EAN_28_10_2005
  9. #include <boost/range.hpp>
  10. #include <boost/mpl/always.hpp>
  11. #include <boost/mpl/placeholders.hpp>
  12. #include <boost/iterator/reverse_iterator.hpp>
  13. #include <boost/iterator/permutation_iterator.hpp>
  14. #include <boost/accumulators/framework/accumulator_base.hpp>
  15. #include <boost/accumulators/framework/extractor.hpp>
  16. #include <boost/accumulators/framework/depends_on.hpp>
  17. #include <boost/accumulators/statistics_fwd.hpp>
  18. #include <boost/accumulators/statistics/tail.hpp>
  19. namespace boost { namespace accumulators
  20. {
  21. namespace impl
  22. {
  23. ///////////////////////////////////////////////////////////////////////////////
  24. // tail_variate_impl
  25. template<typename VariateType, typename VariateTag, typename LeftRight>
  26. struct tail_variate_impl
  27. : accumulator_base
  28. {
  29. // for boost::result_of
  30. typedef
  31. typename detail::tail_range<
  32. typename std::vector<VariateType>::const_iterator
  33. , std::vector<std::size_t>::iterator
  34. >::type
  35. result_type;
  36. template<typename Args>
  37. tail_variate_impl(Args const &args)
  38. : variates(args[tag::tail<LeftRight>::cache_size], args[parameter::keyword<VariateTag>::get() | VariateType()])
  39. {
  40. }
  41. template<typename Args>
  42. void assign(Args const &args, std::size_t index)
  43. {
  44. this->variates[index] = args[parameter::keyword<VariateTag>::get()];
  45. }
  46. template<typename Args>
  47. result_type result(Args const &args) const
  48. {
  49. // getting the order result causes the indices vector to be sorted.
  50. extractor<tag::tail<LeftRight> > const some_tail = {};
  51. return this->do_result(some_tail(args));
  52. }
  53. private:
  54. template<typename TailRng>
  55. result_type do_result(TailRng const &rng) const
  56. {
  57. return detail::make_tail_range(
  58. this->variates.begin()
  59. , rng.end().base().base() // the index iterator
  60. , rng.begin().base().base() // (begin and end reversed because these are reverse iterators)
  61. );
  62. }
  63. std::vector<VariateType> variates;
  64. };
  65. } // namespace impl
  66. ///////////////////////////////////////////////////////////////////////////////
  67. // tag::tail_variate<>
  68. //
  69. namespace tag
  70. {
  71. template<typename VariateType, typename VariateTag, typename LeftRight>
  72. struct tail_variate
  73. : depends_on<tail<LeftRight> >
  74. {
  75. /// INTERNAL ONLY
  76. ///
  77. typedef mpl::always<accumulators::impl::tail_variate_impl<VariateType, VariateTag, LeftRight> > impl;
  78. };
  79. struct abstract_tail_variate
  80. : depends_on<>
  81. {
  82. };
  83. template<typename LeftRight>
  84. struct tail_weights
  85. : depends_on<tail<LeftRight> >
  86. {
  87. /// INTERNAL ONLY
  88. ///
  89. typedef accumulators::impl::tail_variate_impl<mpl::_2, tag::weight, LeftRight> impl;
  90. };
  91. struct abstract_tail_weights
  92. : depends_on<>
  93. {
  94. };
  95. }
  96. ///////////////////////////////////////////////////////////////////////////////
  97. // extract::tail_variate
  98. // extract::tail_weights
  99. //
  100. namespace extract
  101. {
  102. extractor<tag::abstract_tail_variate> const tail_variate = {};
  103. extractor<tag::abstract_tail_weights> const tail_weights = {};
  104. BOOST_ACCUMULATORS_IGNORE_GLOBAL(tail_variate)
  105. BOOST_ACCUMULATORS_IGNORE_GLOBAL(tail_weights)
  106. }
  107. using extract::tail_variate;
  108. using extract::tail_weights;
  109. template<typename VariateType, typename VariateTag, typename LeftRight>
  110. struct feature_of<tag::tail_variate<VariateType, VariateTag, LeftRight> >
  111. : feature_of<tag::abstract_tail_variate>
  112. {
  113. };
  114. template<typename LeftRight>
  115. struct feature_of<tag::tail_weights<LeftRight> >
  116. {
  117. typedef tag::abstract_tail_weights type;
  118. };
  119. }} // namespace boost::accumulators
  120. #endif