times2_iterator.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // times2_iterator.hpp
  3. //
  4. // Copyright 2006 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_TIMES2_ITERATOR_HPP_DE_01_01_2006
  8. #define BOOST_ACCUMULATORS_STATISTICS_TIMES2_ITERATOR_HPP_DE_01_01_2006
  9. #include <functional>
  10. #include <boost/range/begin.hpp>
  11. #include <boost/range/end.hpp>
  12. #include <boost/range/iterator_range.hpp>
  13. #include <boost/iterator/transform_iterator.hpp>
  14. #include <boost/iterator/counting_iterator.hpp>
  15. #include <boost/iterator/permutation_iterator.hpp>
  16. namespace boost { namespace accumulators
  17. {
  18. namespace detail
  19. {
  20. typedef transform_iterator<
  21. std::binder1st<std::multiplies<std::size_t> >
  22. , counting_iterator<std::size_t>
  23. > times2_iterator;
  24. inline times2_iterator make_times2_iterator(std::size_t i)
  25. {
  26. return make_transform_iterator(
  27. make_counting_iterator(i)
  28. , std::bind1st(std::multiplies<std::size_t>(), 2)
  29. );
  30. }
  31. ///////////////////////////////////////////////////////////////////////////////
  32. // lvalue_index_iterator
  33. template<typename Base>
  34. struct lvalue_index_iterator
  35. : Base
  36. {
  37. lvalue_index_iterator(Base base)
  38. : Base(base)
  39. {
  40. }
  41. typename Base::reference operator [](typename Base::difference_type n) const
  42. {
  43. return *(*this + n);
  44. }
  45. };
  46. } // namespace detail
  47. }}
  48. #endif