class pair#( type T1 = int, type T2 = T1 )
Provides a pair that carries two values, which can be different types.
| T1 | optional The type of the first value of a pair. The default is int. |
| T2 | optional The type of the second value of a pair. The default is the same type as T1. |
| pair | Provides a pair that carries two values, which can be different types. |
| Types | |
| this_type | The shorthand of pair#(T1,T2). |
| Properties | |
| first | The first value inside the pair. |
| second | The second value inside the pair. |
| Functions | |
| new | Creates a pair of values of types T1 and T2. |
| eq | Returns 1 if this object is equal to the specified pair. |
| ne | Returns 1 if this object is not equal to the specified pair. |
| lt | Returns 1 if this object is less than the specified pair. |
| gt | Returns 1 if this object is greater than the specified pair. |
| le | Returns 1 if this object is less than or equal to the specified pair. |
| ge | Returns 1 if this object is greater than or equal to the specified pair. |
| clone | Creates a pair by cloning this object. |
| swap | Swaps the contents of this pair with the ones of the specified pair. |
function new( T1 first, T2 second, comparator#(this_type) cmp = null )
Creates a pair of values of types T1 and T2.
| first | The first value of a pair. |
| second | The second value of a pair. |
| cmp | optional A strategy object used to compare two pairs. If not specified or null, pair_comparator #(this_type) is used. The default is null. |
None.
pair#(int, string) p = new( 1, "apple" );
function bit eq( const ref this_type p )
Returns 1 if this object is equal to the specified pair. The comparison is done by the strategy object specified at the object construction.
| p | A pair to compare with. |
If this object is equal to p, then returns 1. Otherwise, returns 0.
pair#(int, string) p = new( 1, "apple" ); pair#(int, string) q = new( 1, "apple" ); assert( p.eq( q ) == 1 ); // 1 == 1 && "apple" == "apple"
function bit ne( const ref this_type p )
Returns 1 if this object is not equal to the specified pair. The comparison is done by the strategy object specified at the object construction.
| p | A pair to compare with. |
If this object is not equal to p, then returns 1. Otherwise, returns 0.
pair#(int, string) p = new( 1, "apple" ); pair#(int, string) q = new( 1, "orange" ); assert( p.ne( q ) == 1 ); // "apple" != "orange"
function bit lt( const ref this_type p )
Returns 1 if this object is less than the specified pair. The comparison is done by the strategy object specified at the object construction.
| p | A pair to compare with. |
If this object is less than p, then returns 1. Otherwise, returns 0.
pair#(int, string) p = new( 1, "apple" ); pair#(int, string) q = new( 2, "apple" ); assert( p.lt( q ) == 1 ); // 1 < 2
function bit gt( const ref this_type p )
Returns 1 if this object is greater than the specified pair. The comparison is done by the strategy object specified at the object construction.
| p | A pair to compare with. |
If this object is greater than p, then returns 1. Otherwise, returns 0.
pair#(int, string) p = new( 1, "orange" ); pair#(int, string) q = new( 1, "apple" ); assert( p.gt( q ) == 1 ); // "orange" > "apple" by the lexicographical order
function bit le( const ref this_type p )
Returns 1 if this object is less than or equal to the specified pair. The comparison is done by the strategy object specified at the object construction.
| p | A pair to compare with. |
If this object is less than or equal to p, then returns 1. Otherwise, returns 0.
pair#(int, string) p = new( 1, "apple" ); pair#(int, string) q = new( 1, "orange" ); assert( p.le( q ) == 1 ); // "apple" < "orange" by the lexicographical order
function bit ge( const ref this_type p )
Returns 1 if this object is greater than or equal to the specified pair. The comparison is done by the strategy object specified at the object construction.
| p | A pair to compare with. |
If this object is greater than or equal to p, then returns 1. Otherwise, returns 0.
pair#(int, string) p = new( 2, "apple" ); pair#(int, string) q = new( 1, "orange" ); assert( p.ge( q ) == 1 ); // 2 > 1
function void swap( ref this_type p )
Swaps the contents of this pair with the ones of the specified pair.
| p | A pair to swap the contents. |
pair#(int, string) p = new( 1, "apple" ); pair#(int, string) q = new( 2, "orange" ); p.swap( q ); assert( p.first == 2 ); assert( q.first == 1 ); assert( p.second == "orange" ); assert( q.second == "apple" );
Provides a pair that carries two values, which can be different types.
class pair#( type T1 = int, type T2 = T1 )
The shorthand of pair#(T1,T2).
typedef pair#( T1, T2 ) this_type
The first value inside the pair.
T1 first
The second value inside the pair.
T2 second
Creates a pair of values of types T1 and T2.
function new( T1 first, T2 second, comparator#(this_type) cmp = null )
Returns 1 if this object is equal to the specified pair.
function bit eq( const ref this_type p )
Returns 1 if this object is not equal to the specified pair.
function bit ne( const ref this_type p )
Returns 1 if this object is less than the specified pair.
function bit lt( const ref this_type p )
Returns 1 if this object is greater than the specified pair.
function bit gt( const ref this_type p )
Returns 1 if this object is less than or equal to the specified pair.
function bit le( const ref this_type p )
Returns 1 if this object is greater than or equal to the specified pair.
function bit ge( const ref this_type p )
Creates a pair by cloning this object.
function this_type clone()
Swaps the contents of this pair with the ones of the specified pair.
function void swap( ref this_type p )
singleton Provides strategies to compare pairs.
class pair_comparator#( type T = pair ) extends comparator#(T)