times2_iterator.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/detail/workaround.hpp>
  11. #include <boost/range/begin.hpp>
  12. #include <boost/range/end.hpp>
  13. #include <boost/range/iterator_range.hpp>
  14. #include <boost/iterator/transform_iterator.hpp>
  15. #include <boost/iterator/counting_iterator.hpp>
  16. #include <boost/iterator/permutation_iterator.hpp>
  17. namespace boost { namespace accumulators
  18. {
  19. namespace detail
  20. {
  21. typedef transform_iterator<
  22. #ifdef BOOST_NO_CXX98_BINDERS
  23. decltype(std::bind(std::multiplies<std::size_t>(), 2, std::placeholders::_1))
  24. #else
  25. std::binder1st<std::multiplies<std::size_t> >
  26. #endif
  27. , counting_iterator<std::size_t>
  28. > times2_iterator;
  29. inline times2_iterator make_times2_iterator(std::size_t i)
  30. {
  31. return make_transform_iterator(
  32. make_counting_iterator(i)
  33. #ifdef BOOST_NO_CXX98_BINDERS
  34. , std::bind(std::multiplies<std::size_t>(), 2, std::placeholders::_1)
  35. #else
  36. , std::bind1st(std::multiplies<std::size_t>(), 2)
  37. #endif
  38. );
  39. }
  40. ///////////////////////////////////////////////////////////////////////////////
  41. // lvalue_index_iterator
  42. template<typename Base>
  43. struct lvalue_index_iterator
  44. : Base
  45. {
  46. lvalue_index_iterator()
  47. : Base()
  48. {}
  49. lvalue_index_iterator(Base base)
  50. : Base(base)
  51. {
  52. }
  53. typename Base::reference operator [](typename Base::difference_type n) const
  54. {
  55. return *(*this + n);
  56. }
  57. };
  58. } // namespace detail
  59. }}
  60. #endif