ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkLexicographicCompare.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18
19#ifndef itkLexicographicCompare_h
20#define itkLexicographicCompare_h
21
22#include <algorithm>
23#include <iterator> // For std::begin, std::end, and reverse_iterator.
24#include "itkMacro.h"
25
26
27/*
28The Functor was only used in one spot in the
29LevelSet class, It does not exist in Slicer, BRAINSTools, Remote modules,
30ANTs, or any other project that I could find.
31*/
32namespace itk::Functor
33{
43{
44public:
45 template <class TAggregateType1, class TAggregateType2>
46 bool
47 operator()(const TAggregateType1 & lhs, const TAggregateType2 & rhs) const
48 {
49 return std::lexicographical_compare(std::begin(lhs), std::end(lhs), std::begin(rhs), std::end(rhs));
50 }
51};
52
53
66{
67public:
68 /* Returns true when lhs comes before rhs. Each argument must be a
69 * bidirectional range, for example an Index or an Offset
70 */
71 template <typename TBidirectionalRange1, typename TBidirectionalRange2>
72 bool
73 operator()(const TBidirectionalRange1 & lhs, const TBidirectionalRange2 & rhs) const
74 {
75 // Note that the begin and end arguments are passed in reverse order, as
76 // each of them is converted to an std::reverse_iterator!
77 return std::lexicographical_compare(std::make_reverse_iterator(std::end(lhs)),
78 std::make_reverse_iterator(std::begin(lhs)),
79 std::make_reverse_iterator(std::end(rhs)),
80 std::make_reverse_iterator(std::begin(rhs)));
81 }
82};
83
84
85} // namespace itk::Functor
86
87#endif
Checks if one range of elements colexicographically comes before another one.
bool operator()(const TBidirectionalRange1 &lhs, const TBidirectionalRange2 &rhs) const
Order Index instances lexicographically.
bool operator()(const TAggregateType1 &lhs, const TAggregateType2 &rhs) const