| 1 |
module imports.test13a; |
| 2 |
|
| 3 |
extern(C) int printf(const char*, ...); |
| 4 |
|
| 5 |
public alias bool boolean; |
| 6 |
public alias int Order; |
| 7 |
public const Order LESS_THAN = -1; |
| 8 |
public const Order EQUALS_TO = 0; |
| 9 |
public const Order GREATER_THAN = +1; |
| 10 |
template Ordinal(T) { |
| 11 |
public T min(T left, T right) { |
| 12 |
return left < right ? left: right; |
| 13 |
} |
| 14 |
public T max(T left, T right) { |
| 15 |
return left > right ? left: right; |
| 16 |
} |
| 17 |
public T clamp(T item, T lower, T upper) |
| 18 |
in { |
| 19 |
assert(lower <= upper); |
| 20 |
} do { |
| 21 |
return max(min(item, upper), lower); |
| 22 |
} |
| 23 |
} |
| 24 |
template TPair(T, U) { |
| 25 |
public class Pair { |
| 26 |
private T _left; |
| 27 |
private U _right; |
| 28 |
public this(T left, U right) { |
| 29 |
this._left = left; |
| 30 |
this._right = right; |
| 31 |
} |
| 32 |
public T left() { |
| 33 |
return this._left; |
| 34 |
} |
| 35 |
public U right() { |
| 36 |
return this._right; |
| 37 |
} |
| 38 |
override public boolean opEquals(Object obj) { |
| 39 |
Pair other = cast(Pair) obj; |
| 40 |
if (other !is null) { |
| 41 |
return (left() == other.left()) && (right() == other.right()); |
| 42 |
} else { |
| 43 |
return false; |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
unittest { |
| 49 |
alias TPair!(char, char) charPair; |
| 50 |
charPair.Pair pairA = new charPair.Pair('a', 'b'); |
| 51 |
charPair.Pair pairB = new charPair.Pair('a', 'b'); |
| 52 |
assert(pairA == pairB); |
| 53 |
printf("Pair tests passed!\r\n"); |
| 54 |
} |