Visual Computing Library
Loading...
Searching...
No Matches
comparators.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_MISC_COMPARATORS_H
24#define VCL_MISC_COMPARATORS_H
25
26#include <algorithm>
27#include <utility>
28
29namespace vcl {
30
38template<typename Pair>
40{
41 bool operator()(const Pair& p1, const Pair& p2) const
42 {
43 if (p1.first == p2.first) {
44 return p1.second < p2.second;
45 }
46 return p1.first < p2.first;
47 }
48};
49
56template<typename T>
58{
59 bool operator()(const std::pair<T, T>& p1, const std::pair<T, T>& p2) const
60 {
61 if (std::min(p1.first, p1.second) < std::min(p2.first, p2.second)) {
62 return true;
63 }
64 else if (
65 std::min(p1.first, p1.second) == std::min(p2.first, p2.second)) {
66 return std::max(p1.first, p1.second) <
67 std::max(p2.first, p2.second);
68 }
69 else {
70 return false;
71 }
72 }
73};
74
83template<typename Pair>
85{
86 bool operator()(const Pair& p1, const Pair& p2) const
87 {
88 return p1.first < p2.first;
89 }
90};
91
92} // namespace vcl
93
94#endif // VCL_MISC_COMPARATORS_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The FirstElementPairComparator struct is an utility comparator that allow to sort std::pair (or any t...
Definition comparators.h:85
The PairComparator struct is an utility comparator to allow to sort pairs in lexical order.
Definition comparators.h:40
The UnorderedPairComparator struct is an utility comparator to allow to sort unordered std::pair<T,...
Definition comparators.h:58