accumulators_fwd.hpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // accumulators_fwd.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_ACCUMULATORS_FWD_HPP_EAN_28_10_2005
  8. #define BOOST_ACCUMULATORS_ACCUMULATORS_FWD_HPP_EAN_28_10_2005
  9. #include <boost/config.hpp>
  10. #include <boost/mpl/apply_fwd.hpp> // for mpl::na
  11. #include <boost/mpl/limits/vector.hpp>
  12. #include <boost/preprocessor/arithmetic/inc.hpp>
  13. #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
  14. #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
  15. #include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
  16. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  17. #include <boost/accumulators/numeric/functional_fwd.hpp>
  18. #ifndef BOOST_ACCUMULATORS_MAX_FEATURES
  19. /// The maximum number of accumulators that may be put in an accumulator_set.
  20. /// Defaults to BOOST_MPL_LIMIT_VECTOR_SIZE (which defaults to 20).
  21. # define BOOST_ACCUMULATORS_MAX_FEATURES BOOST_MPL_LIMIT_VECTOR_SIZE
  22. #endif
  23. #if BOOST_ACCUMULATORS_MAX_FEATURES > BOOST_MPL_LIMIT_VECTOR_SIZE
  24. # error BOOST_ACCUMULATORS_MAX_FEATURES cannot be larger than BOOST_MPL_LIMIT_VECTOR_SIZE
  25. #endif
  26. #ifndef BOOST_ACCUMULATORS_MAX_ARGS
  27. /// The maximum number of arguments that may be specified to an accumulator_set's
  28. /// accumulation function. Defaults to 15.
  29. # define BOOST_ACCUMULATORS_MAX_ARGS 15
  30. #endif
  31. #if BOOST_WORKAROUND(__GNUC__, == 3) \
  32. || BOOST_WORKAROUND(__EDG_VERSION__, BOOST_TESTED_AT(306))
  33. # define BOOST_ACCUMULATORS_BROKEN_CONST_OVERLOADS
  34. #endif
  35. #ifdef BOOST_ACCUMULATORS_BROKEN_CONST_OVERLOADS
  36. # include <boost/utility/enable_if.hpp>
  37. # include <boost/type_traits/is_const.hpp>
  38. # define BOOST_ACCUMULATORS_PROTO_DISABLE_IF_IS_CONST(T)\
  39. , typename boost::disable_if<boost::is_const<T> >::type * = 0
  40. #else
  41. # define BOOST_ACCUMULATORS_PROTO_DISABLE_IF_IS_CONST(T)
  42. #endif
  43. #define BOOST_ACCUMULATORS_GCC_VERSION \
  44. (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
  45. namespace boost { namespace accumulators
  46. {
  47. ///////////////////////////////////////////////////////////////////////////////
  48. // Named parameters tags
  49. //
  50. namespace tag
  51. {
  52. struct sample;
  53. struct weight;
  54. struct accumulator;
  55. struct weights;
  56. }
  57. ///////////////////////////////////////////////////////////////////////////////
  58. // User-level features
  59. //
  60. namespace tag
  61. {
  62. template<typename ValueType, typename Tag>
  63. struct value;
  64. template<typename Tag>
  65. struct value_tag;
  66. template<typename Referent, typename Tag>
  67. struct reference;
  68. template<typename Tag>
  69. struct reference_tag;
  70. template<typename Type, typename Tag = void, typename AccumulatorSet = void>
  71. struct external;
  72. template<typename Feature>
  73. struct droppable;
  74. }
  75. template<typename Accumulator>
  76. struct droppable_accumulator_base;
  77. template<typename Accumulator>
  78. struct droppable_accumulator;
  79. template<typename Accumulator>
  80. struct with_cached_result;
  81. template<typename Sample, typename Features, typename Weight = void>
  82. struct accumulator_set;
  83. template<typename Feature>
  84. struct extractor;
  85. template<typename Feature>
  86. struct feature_of;
  87. template<typename Feature>
  88. struct as_feature;
  89. template<typename Feature>
  90. struct as_weighted_feature;
  91. template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature, mpl::na)>
  92. struct depends_on;
  93. template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature, mpl::na)>
  94. struct features;
  95. template<typename Feature, typename AccumulatorSet>
  96. typename mpl::apply<AccumulatorSet, Feature>::type const &
  97. find_accumulator(AccumulatorSet const &acc);
  98. template<typename Feature, typename AccumulatorSet>
  99. typename mpl::apply<AccumulatorSet, Feature>::type::result_type
  100. extract_result(AccumulatorSet const &acc);
  101. template<typename Feature, typename AccumulatorSet, typename A1>
  102. typename mpl::apply<AccumulatorSet, Feature>::type::result_type
  103. extract_result(AccumulatorSet const &acc, A1 const &a1);
  104. // ... other overloads generated by Boost.Preprocessor:
  105. /// INTERNAL ONLY
  106. ///
  107. #define BOOST_ACCUMULATORS_EXTRACT_RESULT_FWD(z, n, _) \
  108. template< \
  109. typename Feature \
  110. , typename AccumulatorSet \
  111. BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename A) \
  112. > \
  113. typename mpl::apply<AccumulatorSet, Feature>::type::result_type \
  114. extract_result( \
  115. AccumulatorSet const &acc \
  116. BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a) \
  117. );
  118. /// INTERNAL ONLY
  119. ///
  120. BOOST_PP_REPEAT_FROM_TO(
  121. 2
  122. , BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS)
  123. , BOOST_ACCUMULATORS_EXTRACT_RESULT_FWD
  124. , _
  125. )
  126. #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
  127. template<typename Feature, typename AccumulatorSet, typename A1, typename A2 ...>
  128. typename mpl::apply<AccumulatorSet, Feature>::type::result_type
  129. extract_result(AccumulatorSet const &acc, A1 const &a1, A2 const &a2 ...);
  130. #endif
  131. namespace impl
  132. {
  133. using namespace numeric::operators;
  134. template<typename Accumulator, typename Tag>
  135. struct external_impl;
  136. }
  137. namespace detail
  138. {
  139. template<typename Accumulator>
  140. struct feature_tag;
  141. template<typename Feature, typename Sample, typename Weight>
  142. struct to_accumulator;
  143. struct accumulator_set_base;
  144. template<typename T>
  145. struct is_accumulator_set;
  146. inline void ignore_variable(void const *) {}
  147. #define BOOST_ACCUMULATORS_IGNORE_GLOBAL(X) \
  148. namespace detail \
  149. { \
  150. struct BOOST_PP_CAT(ignore_, X) \
  151. { \
  152. void ignore() \
  153. { \
  154. boost::accumulators::detail::ignore_variable(&X); \
  155. } \
  156. }; \
  157. } \
  158. /**/
  159. }
  160. }} // namespace boost::accumulators
  161. // For defining boost::parameter keywords that can be inherited from to
  162. // get a nested, class-scoped keyword with the requested alias
  163. #define BOOST_PARAMETER_NESTED_KEYWORD(tag_namespace, name, alias) \
  164. namespace tag_namespace \
  165. { \
  166. template<int Dummy = 0> \
  167. struct name ## _ \
  168. { \
  169. static char const* keyword_name() \
  170. { \
  171. return #name; \
  172. } \
  173. static ::boost::parameter::keyword<name ## _<Dummy> > &alias; \
  174. }; \
  175. template<int Dummy> \
  176. ::boost::parameter::keyword<name ## _<Dummy> > &name ## _<Dummy>::alias = \
  177. ::boost::parameter::keyword<name ## _<Dummy> >::get(); \
  178. typedef name ## _ <> name; \
  179. } \
  180. namespace \
  181. { \
  182. ::boost::parameter::keyword<tag_namespace::name> &name = \
  183. ::boost::parameter::keyword<tag_namespace::name>::get(); \
  184. }
  185. #endif