Files
enduro2d/headers/3rdparty/flat.hpp/detail/is_sorted.hpp
2019-06-03 22:15:10 +07:00

39 lines
1.2 KiB
C++

/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/flat.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2019, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
namespace flat_hpp::detail
{
template < typename Iter, typename Compare >
bool is_sorted(Iter first, Iter last, Compare comp) {
if ( first != last ) {
Iter next = first;
while ( ++next != last ) {
if ( comp(*next, *first) ) {
return false;
}
++first;
}
}
return true;
}
template < typename Iter, typename Compare >
bool is_sorted_unique(Iter first, Iter last, Compare comp) {
if ( first != last ){
Iter next = first;
while ( ++next != last ) {
if ( !comp(*first, *next) ) {
return false;
}
++first;
}
}
return true;
}
}