ITK  5.2.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  using ReverseIterator1 = std::reverse_iterator<decltype(std::begin(lhs))>;
78  using ReverseIterator2 = std::reverse_iterator<decltype(std::begin(rhs))>;
79 
80  // Note that the begin and end arguments are passed in reverse order, as
81  // each of them is converted to an std::reverse_iterator! (From C++14,
82  // std::make_reverse_iterator would be of help here, to construct the four
83  // std::reverse_iterator arguments!)
84  return std::lexicographical_compare(ReverseIterator1{ std::end(lhs) },
85  ReverseIterator1{ std::begin(lhs) },
86  ReverseIterator2{ std::end(rhs) },
87  ReverseIterator2{ std::begin(rhs) });
88  }
89 };
90 
91 
92 } // end namespace Functor
93 } // end namespace itk
94 
95 #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