| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <testsuite_hooks.h> |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
struct CompLastLt |
| 25 |
{ |
| 26 |
bool operator()(const int x, const int y) |
| 27 |
{ ++itsCount; return x % 10 < y % 10; } |
| 28 |
static int count() { return itsCount; } |
| 29 |
static void reset() { itsCount = 0; } |
| 30 |
static int itsCount; |
| 31 |
}; |
| 32 |
|
| 33 |
int CompLastLt::itsCount; |
| 34 |
|
| 35 |
struct CompLastEq |
| 36 |
{ |
| 37 |
bool operator()(const int x, const int y) |
| 38 |
{ ++itsCount; return x % 10 == y % 10; } |
| 39 |
static int count() { return itsCount; } |
| 40 |
static void reset() { itsCount = 0; } |
| 41 |
static int itsCount; |
| 42 |
}; |
| 43 |
|
| 44 |
int CompLastEq::itsCount; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
template<typename _Tp> |
| 49 |
void |
| 50 |
operations04() |
| 51 |
{ |
| 52 |
typedef _Tp list_type; |
| 53 |
|
| 54 |
const int A[] = {1, 2, 3, 4, 5, 6}; |
| 55 |
const int B[] = {12, 15, 13, 14, 11}; |
| 56 |
const int C[] = {11, 12, 13, 14, 15}; |
| 57 |
const int D[] = {1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6}; |
| 58 |
const int N = sizeof(A) / sizeof(int); |
| 59 |
const int M = sizeof(B) / sizeof(int); |
| 60 |
const int Q = sizeof(D) / sizeof(int); |
| 61 |
|
| 62 |
list_type list0401(A, A + N); |
| 63 |
list_type list0402(B, B + M); |
| 64 |
list_type list0403(C, C + M); |
| 65 |
list_type list0404(D, D + Q); |
| 66 |
list_type list0405(A, A + N); |
| 67 |
|
| 68 |
|
| 69 |
CompLastLt lt; |
| 70 |
|
| 71 |
CompLastLt::reset(); |
| 72 |
list0402.sort(lt); |
| 73 |
VERIFY(list0402 == list0403); |
| 74 |
|
| 75 |
CompLastLt::reset(); |
| 76 |
list0401.merge(list0402, lt); |
| 77 |
VERIFY(list0401 == list0404); |
| 78 |
#ifndef _GLIBCXX_DEBUG |
| 79 |
VERIFY(lt.count() <= (N + M - 1)); |
| 80 |
#endif |
| 81 |
|
| 82 |
CompLastEq eq; |
| 83 |
|
| 84 |
CompLastEq::reset(); |
| 85 |
list0401.unique(eq); |
| 86 |
VERIFY(list0401 == list0405); |
| 87 |
#ifndef _GLIBCXX_DEBUG |
| 88 |
VERIFY(eq.count() == (N + M - 1)); |
| 89 |
#endif |
| 90 |
} |
| 91 |
|