mirror of
https://github.com/monero-project/monero.git
synced 2024-10-01 11:49:47 -04:00
adjust is_sorted_and_unique()
This commit is contained in:
parent
3d60475753
commit
73298734d6
@ -47,21 +47,20 @@
|
|||||||
namespace tools
|
namespace tools
|
||||||
{
|
{
|
||||||
|
|
||||||
/// use operator< to get operator==
|
/// test if a container is sorted and unique according to a comparison criteria (defaults to operator<)
|
||||||
/// WARNING: equality is not always implied by operator<, depending on implementation
|
template <typename T, typename ComparisonOpT = std::less<typename T::value_type>>
|
||||||
struct equals_from_less final
|
bool is_sorted_and_unique(const T &container, const ComparisonOpT &ComparisonOp = ComparisonOpT{})
|
||||||
{
|
{
|
||||||
template <typename T>
|
if (!std::is_sorted(container.begin(), container.end(), ComparisonOp))
|
||||||
bool operator()(const T &a, const T &b) { return !(a < b) && !(b < a); }
|
|
||||||
};
|
|
||||||
/// note: test for sorted and uniqueness using the same criteria (operator<)
|
|
||||||
template <typename T>
|
|
||||||
bool is_sorted_and_unique(const T& container)
|
|
||||||
{
|
|
||||||
if (!std::is_sorted(container.begin(), container.end()))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (std::adjacent_find(container.begin(), container.end(), equals_from_less{}) != container.end())
|
if (std::adjacent_find(container.begin(),
|
||||||
|
container.end(),
|
||||||
|
[&ComparisonOp](const typename T::value_type &a, const typename T::value_type &b) -> bool
|
||||||
|
{
|
||||||
|
return !ComparisonOp(a, b) && !ComparisonOp(b, a);
|
||||||
|
})
|
||||||
|
!= container.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user