ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkLexicographicCompare.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 operator()(const TAggregateType1 &lhs, const TAggregateType2 &rhs) const
49  {
50  return std::lexicographical_compare(
51  std::begin(lhs), std::end(lhs),
52  std::begin(rhs), std::end(rhs));
53  }
54 };
55 
56 
69 {
70 public:
71  /* Returns true when lhs comes before rhs. Each argument must be a
72  * bidirectional range, for example an Index or an Offset
73  */
74  template< typename TBidirectionalRange1, typename TBidirectionalRange2 >
75  bool 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(
85  ReverseIterator1{ std::end(lhs) },
86  ReverseIterator1{ std::begin(lhs) },
87  ReverseIterator2{ std::end(rhs) },
88  ReverseIterator2{ std::begin(rhs) });
89  }
90 };
91 
92 
93 } //end namespace Functor
94 } //end namespace itk
95 
96 #endif
bool operator()(const TBidirectionalRange1 &lhs, const TBidirectionalRange2 &rhs) const
bool operator()(const TAggregateType1 &lhs, const TAggregateType2 &rhs) const
Order Index instances lexicographically.
Checks if one range of elements colexicographically comes before another one.