Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:25

0001 /*
0002    Copyright (c) T. Zachary Laine 2018.
0003 
0004    Distributed under the Boost Software License, Version 1.0. (See accompanying
0005    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 */
0007 #ifndef BOOST_ALGORITHM_FIND_BACKWARD_HPP
0008 #define BOOST_ALGORITHM_FIND_BACKWARD_HPP
0009 
0010 #include <utility>
0011 
0012 #include <boost/config.hpp>
0013 #include <boost/range/begin.hpp>
0014 #include <boost/range/end.hpp>
0015 
0016 namespace boost { namespace algorithm {
0017 
0018 template<typename BidiIter, typename T>
0019 BOOST_CXX14_CONSTEXPR
0020 BidiIter find_backward(BidiIter first, BidiIter last, const T & x)
0021 {
0022     BidiIter it = last;
0023     while (it != first) {
0024         if (*--it == x)
0025             return it;
0026     }
0027     return last;
0028 }
0029 
0030 template<typename Range, typename T>
0031 BOOST_CXX14_CONSTEXPR
0032 typename boost::range_iterator<Range>::type find_backward(Range & range, const T & x)
0033 {
0034     return ::boost::algorithm::find_backward(boost::begin(range), boost::end(range), x);
0035 }
0036 
0037 template<typename BidiIter, typename T>
0038 BOOST_CXX14_CONSTEXPR
0039 BidiIter find_not_backward(BidiIter first, BidiIter last, const T & x)
0040 {
0041     BidiIter it = last;
0042     while (it != first) {
0043         if (*--it != x)
0044             return it;
0045     }
0046     return last;
0047 }
0048 
0049 template<typename Range, typename T>
0050 BOOST_CXX14_CONSTEXPR
0051 typename boost::range_iterator<Range>::type find_not_backward(Range & range, const T & x)
0052 {
0053     return ::boost::algorithm::find_not_backward(boost::begin(range), boost::end(range), x);
0054 }
0055 
0056 template<typename BidiIter, typename Pred>
0057 BOOST_CXX14_CONSTEXPR
0058 BidiIter find_if_backward(BidiIter first, BidiIter last, Pred p)
0059 {
0060     BidiIter it = last;
0061     while (it != first) {
0062         if (p(*--it))
0063             return it;
0064     }
0065     return last;
0066 }
0067 
0068 template<typename Range, typename Pred>
0069 BOOST_CXX14_CONSTEXPR
0070 typename boost::range_iterator<Range>::type find_if_backward(Range & range, Pred p)
0071 {
0072     return ::boost::algorithm::find_if_backward(boost::begin(range), boost::end(range), p);
0073 }
0074 
0075 template<typename BidiIter, typename Pred>
0076 BOOST_CXX14_CONSTEXPR
0077 BidiIter find_if_not_backward(BidiIter first, BidiIter last, Pred p)
0078 {
0079     BidiIter it = last;
0080     while (it != first) {
0081         if (!p(*--it))
0082             return it;
0083     }
0084     return last;
0085 }
0086 
0087 template<typename Range, typename Pred>
0088 BOOST_CXX14_CONSTEXPR
0089 typename boost::range_iterator<Range>::type find_if_not_backward(Range & range, Pred p)
0090 {
0091     return ::boost::algorithm::find_if_not_backward(boost::begin(range), boost::end(range), p);
0092 }
0093 
0094 }} // namespace boost and algorithm
0095 
0096 #endif // BOOST_ALGORITHM_FIND_BACKWARD_HPP