123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- #ifndef BOOST_ALGORITHM_ORDERED_HPP
- #define BOOST_ALGORITHM_ORDERED_HPP
- #include <functional>
- #include <iterator>
- #include <boost/config.hpp>
- #include <boost/range/begin.hpp>
- #include <boost/range/end.hpp>
- #include <boost/core/enable_if.hpp>
- #include <boost/type_traits/is_same.hpp>
- #include <boost/type_traits/type_identity.hpp> // for boost::type_identity
- namespace boost { namespace algorithm {
- template <typename ForwardIterator, typename Pred>
- BOOST_CXX14_CONSTEXPR ForwardIterator is_sorted_until ( ForwardIterator first, ForwardIterator last, Pred p )
- {
- if ( first == last ) return last;
- ForwardIterator next = first;
- while ( ++next != last )
- {
- if ( p ( *next, *first ))
- return next;
- first = next;
- }
- return last;
- }
- template <typename ForwardIterator>
- BOOST_CXX14_CONSTEXPR ForwardIterator is_sorted_until ( ForwardIterator first, ForwardIterator last )
- {
- typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
- return boost::algorithm::is_sorted_until ( first, last, std::less<value_type>());
- }
- template <typename ForwardIterator, typename Pred>
- BOOST_CXX14_CONSTEXPR bool is_sorted ( ForwardIterator first, ForwardIterator last, Pred p )
- {
- return boost::algorithm::is_sorted_until (first, last, p) == last;
- }
- template <typename ForwardIterator>
- BOOST_CXX14_CONSTEXPR bool is_sorted ( ForwardIterator first, ForwardIterator last )
- {
- return boost::algorithm::is_sorted_until (first, last) == last;
- }
- template <typename R, typename Pred>
- BOOST_CXX14_CONSTEXPR typename boost::lazy_disable_if_c<
- boost::is_same<R, Pred>::value,
- typename boost::range_iterator<const R>
- >::type is_sorted_until ( const R &range, Pred p )
- {
- return boost::algorithm::is_sorted_until ( boost::begin ( range ), boost::end ( range ), p );
- }
- template <typename R>
- BOOST_CXX14_CONSTEXPR typename boost::range_iterator<const R>::type is_sorted_until ( const R &range )
- {
- return boost::algorithm::is_sorted_until ( boost::begin ( range ), boost::end ( range ));
- }
- template <typename R, typename Pred>
- BOOST_CXX14_CONSTEXPR typename boost::lazy_disable_if_c< boost::is_same<R, Pred>::value, boost::type_identity<bool> >::type
- is_sorted ( const R &range, Pred p )
- {
- return boost::algorithm::is_sorted ( boost::begin ( range ), boost::end ( range ), p );
- }
- template <typename R>
- BOOST_CXX14_CONSTEXPR bool is_sorted ( const R &range )
- {
- return boost::algorithm::is_sorted ( boost::begin ( range ), boost::end ( range ));
- }
- template <typename ForwardIterator>
- BOOST_CXX14_CONSTEXPR bool is_increasing ( ForwardIterator first, ForwardIterator last )
- {
- typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
- return boost::algorithm::is_sorted (first, last, std::less<value_type>());
- }
- template <typename R>
- BOOST_CXX14_CONSTEXPR bool is_increasing ( const R &range )
- {
- return is_increasing ( boost::begin ( range ), boost::end ( range ));
- }
- template <typename ForwardIterator>
- BOOST_CXX14_CONSTEXPR bool is_decreasing ( ForwardIterator first, ForwardIterator last )
- {
- typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
- return boost::algorithm::is_sorted (first, last, std::greater<value_type>());
- }
- template <typename R>
- BOOST_CXX14_CONSTEXPR bool is_decreasing ( const R &range )
- {
- return is_decreasing ( boost::begin ( range ), boost::end ( range ));
- }
- template <typename ForwardIterator>
- BOOST_CXX14_CONSTEXPR bool is_strictly_increasing ( ForwardIterator first, ForwardIterator last )
- {
- typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
- return boost::algorithm::is_sorted (first, last, std::less_equal<value_type>());
- }
- template <typename R>
- BOOST_CXX14_CONSTEXPR bool is_strictly_increasing ( const R &range )
- {
- return is_strictly_increasing ( boost::begin ( range ), boost::end ( range ));
- }
- template <typename ForwardIterator>
- BOOST_CXX14_CONSTEXPR bool is_strictly_decreasing ( ForwardIterator first, ForwardIterator last )
- {
- typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
- return boost::algorithm::is_sorted (first, last, std::greater_equal<value_type>());
- }
- template <typename R>
- BOOST_CXX14_CONSTEXPR bool is_strictly_decreasing ( const R &range )
- {
- return is_strictly_decreasing ( boost::begin ( range ), boost::end ( range ));
- }
- }}
- #endif
|