/Src/Dependencies/Boost/boost/accumulators/framework/accumulators/external_accumulator.hpp

http://hadesmem.googlecode.com/ · C++ Header · 108 lines · 70 code · 16 blank · 22 comment · 0 complexity · 3dc53ed0dc2259bbd012c6df0963433b MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // external_accumulator.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_FRAMEWORK_ACCUMULATORS_EXTERNAL_ACCUMULATOR_HPP_EAN_01_12_2005
  8. #define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_EXTERNAL_ACCUMULATOR_HPP_EAN_01_12_2005
  9. #include <boost/mpl/placeholders.hpp>
  10. #include <boost/parameter/keyword.hpp>
  11. #include <boost/accumulators/framework/extractor.hpp>
  12. #include <boost/accumulators/framework/depends_on.hpp> // for feature_tag
  13. #include <boost/accumulators/framework/accumulator_base.hpp>
  14. #include <boost/accumulators/framework/accumulators/reference_accumulator.hpp>
  15. namespace boost { namespace accumulators { namespace impl
  16. {
  17. //////////////////////////////////////////////////////////////////////////
  18. // external_impl
  19. /// INTERNAL ONLY
  20. ///
  21. template<typename Accumulator, typename Tag>
  22. struct external_impl
  23. : accumulator_base
  24. {
  25. typedef typename Accumulator::result_type result_type;
  26. typedef typename detail::feature_tag<Accumulator>::type feature_tag;
  27. external_impl(dont_care) {}
  28. template<typename Args>
  29. result_type result(Args const &args) const
  30. {
  31. return this->extract_(args, args[parameter::keyword<Tag>::get() | 0]);
  32. }
  33. private:
  34. template<typename Args>
  35. static result_type extract_(Args const &args, int)
  36. {
  37. // No named parameter passed to the extractor. Maybe the external
  38. // feature is held by reference<>.
  39. extractor<feature_tag> extract;
  40. return extract(accumulators::reference_tag<Tag>(args));
  41. }
  42. template<typename Args, typename AccumulatorSet>
  43. static result_type extract_(Args const &, AccumulatorSet const &acc)
  44. {
  45. // OK, a named parameter for this external feature was passed to the
  46. // extractor, so use that.
  47. extractor<feature_tag> extract;
  48. return extract(acc);
  49. }
  50. };
  51. } // namespace impl
  52. namespace tag
  53. {
  54. //////////////////////////////////////////////////////////////////////////
  55. // external
  56. template<typename Feature, typename Tag, typename AccumulatorSet>
  57. struct external
  58. : depends_on<reference<AccumulatorSet, Tag> >
  59. {
  60. typedef
  61. accumulators::impl::external_impl<
  62. detail::to_accumulator<Feature, mpl::_1, mpl::_2>
  63. , Tag
  64. >
  65. impl;
  66. };
  67. template<typename Feature, typename Tag>
  68. struct external<Feature, Tag, void>
  69. : depends_on<>
  70. {
  71. typedef
  72. accumulators::impl::external_impl<
  73. detail::to_accumulator<Feature, mpl::_1, mpl::_2>
  74. , Tag
  75. >
  76. impl;
  77. };
  78. }
  79. // for the purposes of feature-based dependency resolution,
  80. // external_accumulator<Feature, Tag> provides the same feature as Feature
  81. template<typename Feature, typename Tag, typename AccumulatorSet>
  82. struct feature_of<tag::external<Feature, Tag, AccumulatorSet> >
  83. : feature_of<Feature>
  84. {
  85. };
  86. // Note: Usually, the extractor is pulled into the accumulators namespace with
  87. // a using directive, not the tag. But the external<> feature doesn't have an
  88. // extractor, so we can put the external tag in the accumulators namespace
  89. // without fear of a name conflict.
  90. using tag::external;
  91. }} // namespace boost::accumulators
  92. #endif