ITK  5.3.0
Insight Toolkit
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  * http://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 namespace itk
27 {
28 
29 /*
30 The Functor was only used in one spot in the
31 LevelSet class, It does not exist in Slicer, BRAINSTools, Remote modules,
32 ANTs, or any other project that I could find.
33 */
34 namespace Functor
35 {
45 {
46 public:
47  template <class TAggregateType1, class TAggregateType2>
48  bool
49  operator()(const TAggregateType1 & lhs, const TAggregateType2 & rhs) const
50  {
51  return std::lexicographical_compare(std::begin(lhs), std::end(lhs), std::begin(rhs), std::end(rhs));
52  }
53 };
54 
55 
68 {
69 public:
70  /* Returns true when lhs comes before rhs. Each argument must be a
71  * bidirectional range, for example an Index or an Offset
72  */
73  template <typename TBidirectionalRange1, typename TBidirectionalRange2>
74  bool
75  operator()(const TBidirectionalRange1 & lhs, const TBidirectionalRange2 & rhs) const
76  {
77  // Note that the begin and end arguments are passed in reverse order, as
78  // each of them is converted to an std::reverse_iterator!
79  return std::lexicographical_compare(std::make_reverse_iterator(std::end(lhs)),
80  std::make_reverse_iterator(std::begin(lhs)),
81  std::make_reverse_iterator(std::end(rhs)),
82  std::make_reverse_iterator(std::begin(rhs)));
83  }
84 };
85 
86 
87 } // end namespace Functor
88 } // end namespace itk
89 
90 #endif
itk::Functor::CoLexicographicCompare
Checks if one range of elements colexicographically comes before another one.
Definition: itkLexicographicCompare.h:67
itkMacro.h
itk::Functor::LexicographicCompare::operator()
bool operator()(const TAggregateType1 &lhs, const TAggregateType2 &rhs) const
Definition: itkLexicographicCompare.h:49
itk::Functor::LexicographicCompare
Order Index instances lexicographically.
Definition: itkLexicographicCompare.h:44
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Functor::CoLexicographicCompare::operator()
bool operator()(const TBidirectionalRange1 &lhs, const TBidirectionalRange2 &rhs) const
Definition: itkLexicographicCompare.h:75