error_of.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // error_of.hpp
  3. //
  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)
  7. #ifndef BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_HPP_EAN_29_11_2005
  8. #define BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_HPP_EAN_29_11_2005
  9. #include <boost/mpl/placeholders.hpp>
  10. #include <boost/accumulators/framework/accumulator_base.hpp>
  11. #include <boost/accumulators/framework/extractor.hpp>
  12. #include <boost/accumulators/framework/depends_on.hpp>
  13. #include <boost/accumulators/statistics_fwd.hpp>
  14. namespace boost { namespace accumulators
  15. {
  16. namespace impl
  17. {
  18. /// INTERNAL ONLY
  19. ///
  20. template<typename Feature>
  21. struct this_feature_has_no_error_calculation
  22. : mpl::false_
  23. {
  24. };
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // error_of_impl
  27. /// INTERNAL ONLY
  28. ///
  29. template<typename Sample, typename Feature>
  30. struct error_of_impl
  31. : accumulator_base
  32. {
  33. // TODO: specialize this on the specific features that have errors we're
  34. // interested in.
  35. BOOST_MPL_ASSERT((this_feature_has_no_error_calculation<Feature>));
  36. // for boost::result_of
  37. typedef int result_type;
  38. error_of_impl(dont_care)
  39. {
  40. }
  41. result_type result(dont_care) const
  42. {
  43. return 0;
  44. }
  45. };
  46. } // namespace impl
  47. ///////////////////////////////////////////////////////////////////////////////
  48. // tag::error_of
  49. //
  50. namespace tag
  51. {
  52. template<typename Feature>
  53. struct error_of
  54. : depends_on<Feature>
  55. {
  56. /// INTERNAL ONLY
  57. ///
  58. typedef accumulators::impl::error_of_impl<mpl::_1, Feature> impl;
  59. };
  60. }
  61. ///////////////////////////////////////////////////////////////////////////////
  62. // extract::error_of
  63. //
  64. namespace extract
  65. {
  66. BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, error_of, (typename))
  67. }
  68. using extract::error_of;
  69. // make tag::error_of<tag::feature(modifier)> work
  70. template<typename Feature>
  71. struct as_feature<tag::error_of<Feature> >
  72. {
  73. typedef tag::error_of<typename as_feature<Feature>::type> type;
  74. };
  75. // make error_of<tag::mean> work with non-void weights (should become
  76. // error_of<tag::weighted_mean>
  77. template<typename Feature>
  78. struct as_weighted_feature<tag::error_of<Feature> >
  79. {
  80. typedef tag::error_of<typename as_weighted_feature<Feature>::type> type;
  81. };
  82. }} // namespace boost::accumulators
  83. #endif