reverse.hppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef ADOBE_ALGORITHM_REVERSE_HPP
00009 #define ADOBE_ALGORITHM_REVERSE_HPP
00010
00011 #include <adobe/config.hpp>
00012
00013 #include <boost/range/begin.hpp>
00014 #include <boost/range/end.hpp>
00015 #include <boost/range/iterator.hpp>
00016
00017 #include <adobe/iterator/set_next.hpp>
00018
00019 #include <algorithm>
00020 #include <utility>
00021
00022
00023
00024 namespace adobe {
00025
00026
00035
00036
00037 namespace unsafe {
00038
00039
00040
00044 template <typename I>
00045 I reverse_append(I first, I last, I result)
00046 {
00047 while (first != last)
00048 {
00049 I prior(first);
00050 ++first;
00051 adobe::unsafe::set_next(prior, result);
00052 result = prior;
00053 }
00054 return result;
00055 }
00056
00060 template <typename R,
00061 typename I>
00062 inline I reverse_append(R& range, I result)
00063 {
00064 return adobe::unsafe::reverse_append(boost::begin(range), boost::end(range), result);
00065 }
00066
00070 template <typename I>
00071 inline I reverse_nodes(I first, I last)
00072 {
00073 return adobe::unsafe::reverse_append(first, last, last);
00074 }
00075
00079 template <typename R>
00080 inline typename boost::range_iterator<R>::type reverse_nodes(R& range)
00081 {
00082 return adobe::unsafe::reverse_nodes(boost::begin(range), boost::end(range));
00083 }
00084
00085
00086
00087 }
00088
00089
00095 template <class BidirectionalRange>
00096 inline void reverse(BidirectionalRange& range)
00097 {
00098 std::reverse(boost::begin(range), boost::end(range));
00099 }
00100
00106 template <class BidirectionalRange, class OutputIterator>
00107 inline void reverse_copy(BidirectionalRange& range, OutputIterator result)
00108 {
00109 std::reverse_copy(boost::begin(range), boost::end(range), result);
00110 }
00111
00117 template <class BidirectionalRange, class OutputIterator>
00118 inline void reverse_copy(const BidirectionalRange& range, OutputIterator result)
00119 {
00120 std::reverse_copy(boost::begin(range), boost::end(range), result);
00121 }
00122
00123
00129 template <typename I>
00130 std::pair<I, I> reverse_until(I f, I m, I l)
00131 {
00132 while (f != m && m != l)
00133 {
00134 --l;
00135
00136 std::iter_swap(f, l);
00137
00138 ++f;
00139 }
00140
00141 return std::pair<I, I>(f, l);
00142 }
00143
00144
00145
00146 }
00147
00148
00149
00150 #endif
00151
00152
|