reverse.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright Neil Groves 2009. Use, modification and
  2. // distribution is subject to the Boost Software License, Version
  3. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. //
  7. // For more information, see http://www.boost.org/libs/range/
  8. //
  9. #ifndef BOOST_RANGE_ALGORITHM_REVERSE_HPP_INCLUDED
  10. #define BOOST_RANGE_ALGORITHM_REVERSE_HPP_INCLUDED
  11. #include <boost/concept_check.hpp>
  12. #include <boost/range/begin.hpp>
  13. #include <boost/range/end.hpp>
  14. #include <boost/range/concepts.hpp>
  15. #include <boost/range/detail/range_return.hpp>
  16. #include <algorithm>
  17. namespace boost
  18. {
  19. namespace range
  20. {
  21. /// \brief template function reverse
  22. ///
  23. /// range-based version of the reverse std algorithm
  24. ///
  25. /// \pre BidirectionalRange is a model of the BidirectionalRangeConcept
  26. template<class BidirectionalRange>
  27. inline BidirectionalRange& reverse(BidirectionalRange& rng)
  28. {
  29. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<BidirectionalRange> ));
  30. std::reverse(boost::begin(rng), boost::end(rng));
  31. return rng;
  32. }
  33. /// \overload
  34. template<class BidirectionalRange>
  35. inline const BidirectionalRange& reverse(const BidirectionalRange& rng)
  36. {
  37. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<const BidirectionalRange> ));
  38. std::reverse(boost::begin(rng), boost::end(rng));
  39. return rng;
  40. }
  41. } // namespace range
  42. using range::reverse;
  43. } // namespace boost
  44. #endif // include guard