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

http://hadesmem.googlecode.com/ · C++ Header · 89 lines · 57 code · 14 blank · 18 comment · 0 complexity · 518814f1e1b707f4bf17d6dbda8d4bf2 MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // reference_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_REFERENCE_ACCUMULATOR_HPP_EAN_03_23_2006
  8. #define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_REFERENCE_ACCUMULATOR_HPP_EAN_03_23_2006
  9. #include <boost/ref.hpp>
  10. #include <boost/mpl/always.hpp>
  11. #include <boost/parameter/keyword.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/extractor.hpp>
  15. namespace boost { namespace accumulators
  16. {
  17. namespace impl
  18. {
  19. //////////////////////////////////////////////////////////////////////////
  20. // reference_accumulator_impl
  21. //
  22. template<typename Referent, typename Tag>
  23. struct reference_accumulator_impl
  24. : accumulator_base
  25. {
  26. typedef Referent &result_type;
  27. template<typename Args>
  28. reference_accumulator_impl(Args const &args)
  29. : ref(args[parameter::keyword<Tag>::get()])
  30. {
  31. }
  32. result_type result(dont_care) const
  33. {
  34. return this->ref;
  35. }
  36. private:
  37. reference_wrapper<Referent> ref;
  38. };
  39. } // namespace impl
  40. namespace tag
  41. {
  42. //////////////////////////////////////////////////////////////////////////
  43. // reference_tag
  44. template<typename Tag>
  45. struct reference_tag
  46. {
  47. };
  48. //////////////////////////////////////////////////////////////////////////
  49. // reference
  50. template<typename Referent, typename Tag>
  51. struct reference
  52. : depends_on<>
  53. {
  54. /// INTERNAL ONLY
  55. ///
  56. typedef mpl::always<accumulators::impl::reference_accumulator_impl<Referent, Tag> > impl;
  57. };
  58. }
  59. namespace extract
  60. {
  61. BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, reference, (typename)(typename))
  62. BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, reference_tag, (typename))
  63. }
  64. using extract::reference;
  65. using extract::reference_tag;
  66. // Map all reference<V,T> features to reference_tag<T> so
  67. // that references can be extracted using reference_tag<T>
  68. // without specifying the referent type.
  69. template<typename ValueType, typename Tag>
  70. struct feature_of<tag::reference<ValueType, Tag> >
  71. : feature_of<tag::reference_tag<Tag> >
  72. {
  73. };
  74. }} // namespace boost::accumulators
  75. #endif