adjacent_zippedでソート済みかを判定する

OvenToBoostにあるadjacent_zippedの利用例です。
このRangeアダプタを使うと、is_sorted()が簡単に書けます。

#include <boost/range/adaptor/adjacent_zipped.hpp>
#include <boost/range/value_type.hpp>
#include <boost/algorithm/cxx11/all_of.hpp>

template <class BidirectionalRange>
bool is_sorted(const BidirectionalRange& r)
{
    typedef typename boost::range_value<BidirectionalRange>::type value_type;
    using namespace boost::adaptors;

    return boost::algorithm::all_of(
                 r | adjacent_zipped,
                 [](const boost::tuple<value_type, value_type>& x) {
                    return boost::get<0>(x) < boost::get<1>(x);
                 });
}

#include <iostream>
#include <vector>
#include <boost/range/algorithm/sort.hpp>

int main()
{
    std::vector<int> v = {3, 1, 4};

    std::cout << std::boolalpha;
    std::cout << ::is_sorted(v) << std::endl;

    boost::sort(v);
    std::cout << ::is_sorted(v) << std::endl;
}
false
true