@@ -165,7 +165,6 @@ macro_rules! tuple_impls(
165
165
fn eq( & self , other: & ( $( $T) ,+) ) -> bool {
166
166
$( * self . $get_ref_fn( ) == * other. $get_ref_fn( ) ) &&+
167
167
}
168
-
169
168
#[ inline( always) ]
170
169
fn ne( & self , other: & ( $( $T) ,+) ) -> bool {
171
170
!( * self == * other)
@@ -176,29 +175,30 @@ macro_rules! tuple_impls(
176
175
impl <$( $T: Ord ) ,+> Ord for ( $( $T) ,+) {
177
176
#[ inline( always) ]
178
177
fn lt( & self , other: & ( $( $T) ,+) ) -> bool {
179
- $( * self . $get_ref_fn( ) < * other. $get_ref_fn( ) ) &&+
178
+ lexical_lt! ( $( * self . $get_ref_fn( ) , * other. $get_ref_fn( ) ) ,+ )
180
179
}
181
-
182
180
#[ inline( always) ]
183
- fn le( & self , other: & ( $( $T) ,+) ) -> bool {
184
- $( * self . $get_ref_fn( ) <= * other. $get_ref_fn( ) ) &&+
185
- }
186
-
181
+ fn le( & self , other: & ( $( $T) ,+) ) -> bool { !( * other) . lt( & ( * self ) ) }
187
182
#[ inline( always) ]
188
- fn ge( & self , other: & ( $( $T) ,+) ) -> bool {
189
- $( * self . $get_ref_fn( ) >= * other. $get_ref_fn( ) ) &&+
190
- }
191
-
183
+ fn ge( & self , other: & ( $( $T) ,+) ) -> bool { !( * self ) . lt( other) }
192
184
#[ inline( always) ]
193
- fn gt( & self , other: & ( $( $T) ,+) ) -> bool {
194
- $( * self . $get_ref_fn( ) > * other. $get_ref_fn( ) ) &&+
195
- }
185
+ fn gt( & self , other: & ( $( $T) ,+) ) -> bool { ( * other) . lt( & ( * self ) ) }
196
186
}
197
187
) +
198
188
}
199
189
)
200
190
)
201
191
192
+ // Constructs an expression that performs a lexical less-than ordering.
193
+ // The values are interleaved, so the macro invocation for
194
+ // `(a1, a2, a3) < (b1, b2, b3)` would be `lexical_lt!(a1, b1, a2, b2, a3, b3)`
195
+ macro_rules! lexical_lt(
196
+ ( $a: expr, $b: expr, $( $rest_a: expr, $rest_b: expr) ,+) => (
197
+ if $a < $b { true } else { lexical_lt!( $( $rest_a, $rest_b) ,+) }
198
+ ) ;
199
+ ( $a: expr, $b: expr) => ( $a < $b) ;
200
+ )
201
+
202
202
tuple_impls ! (
203
203
( CloneableTuple2 , ImmutableTuple2 ) {
204
204
( n0, n0_ref) -> A { ( ref a, _) => a }
0 commit comments