auto_iterator.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Copyright 2016 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See http://www.boost.org/libs/poly_collection for library home page.
  7. */
  8. #ifndef BOOST_POLY_COLLECTION_DETAIL_AUTO_ITERATOR_HPP
  9. #define BOOST_POLY_COLLECTION_DETAIL_AUTO_ITERATOR_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/iterator/iterator_adaptor.hpp>
  14. namespace boost{
  15. namespace poly_collection{
  16. namespace detail{
  17. /* auto_iterator<Iterator> (for want of a better name) behaves like Iterator
  18. * save for the fact that it derefs to Iterator& rather than
  19. * Iterator::reference. This is useful to "lift" std algorithms so that
  20. * user-defined predicates are passed iterators that can then be dereferenced
  21. * internally.
  22. */
  23. template<typename Iterator>
  24. class auto_iterator:
  25. public boost::iterator_adaptor<auto_iterator<Iterator>,Iterator,Iterator>
  26. {
  27. public:
  28. auto_iterator()=default;
  29. auto_iterator(const Iterator& it):auto_iterator::iterator_adaptor_{it}{}
  30. auto_iterator(const auto_iterator&)=default;
  31. auto_iterator& operator=(const auto_iterator&)=default;
  32. private:
  33. friend class boost::iterator_core_access;
  34. Iterator& dereference()const noexcept
  35. {
  36. return const_cast<auto_iterator*>(this)->base_reference();
  37. }
  38. };
  39. } /* namespace poly_collection::detail */
  40. } /* namespace poly_collection */
  41. } /* namespace boost */
  42. #endif