-
Notifications
You must be signed in to change notification settings - Fork 7
/
utils.functor.pas
477 lines (446 loc) · 20 KB
/
utils.functor.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
(******************************************************************************)
(* PascalUtils *)
(* delphi and object pascal library of utils data structures *)
(* *)
(* Copyright (c) 2020 Ivan Semenkov *)
(* https://github.com/isemenkov/pascalutils ivan@semenkov.pro *)
(* Ukraine *)
(******************************************************************************)
(* *)
(* Permission is hereby granted, free of charge, to any person obtaining a *)
(* copy of this software and associated documentation files (the "Software"), *)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
(* and/or sell copies of the Software, and to permit persons to whom the *)
(* Software is furnished to do so, subject to the following conditions: *)
(* *)
(* The above copyright notice and this permission notice shall be included in *)
(* all copies or substantial portions of the Software. *)
(* *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
(* DEALINGS IN THE SOFTWARE. *)
(* *)
(******************************************************************************)
unit utils.functor;
{$IFDEF FPC}
{$mode objfpc}{$H+}
{$ENDIF}
{$IFOPT D+}
{$DEFINE DEBUG}
{$ENDIF}
interface
uses
SysUtils, utils.pair{$IFNDEF FPC}, System.Generics.Defaults{$ENDIF};
type
{ Base unary functor }
{$IFDEF FPC}generic{$ENDIF} TUnaryFunctor<V, R> = class
public
function Call(AValue : V) : R; virtual; abstract;
end;
{ Base binary functor }
{$IFDEF FPC}generic{$ENDIF} TBinaryFunctor<V, R> = class
public
function Call(AValue1, AValue2 : V) : R; virtual; abstract;
end;
{ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Compare functor
Return a negative value if value1 should be sorted before value2, a positive
value if value1 should be sorted after value2, zero if value1 and value2 are
equal.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= }
{$IFDEF FPC}generic{$ENDIF} TDefaultCompareFunctor<V> =
class({$IFDEF FPC}specialize{$ENDIF} TBinaryFunctor<V, Integer>)
public
function Call(AValue1, AValue2 : V) : Integer; override;
end;
{ Functors for default types. }
TCompareFunctorByte =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<Byte>);
TCompareFunctorShortInt =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<ShortInt>);
TCompareFunctorWord =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<Word>);
TCompareFunctorSmallInt =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<SmallInt>);
TCompareFunctorInteger =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<Integer>);
{$IFDEF FPC}
TCompareFunctorDWord =
class(specialize TDefaultCompareFunctor<DWord>);
{$ENDIF}
TCompareFunctorCardinal =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<Cardinal>);
TCompareFunctorLongWord =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<LongWord>);
TCompareFunctorLongInt =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<LongInt>);
{$IFDEF FPC}
TCompareFunctorQWord =
class(specialize TDefaultCompareFunctor<QWord>);
{$ENDIF}
TCompareFunctorInt64 =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<Int64>);
TCompareFunctorSingle =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<Single>);
TCompareFunctorReal =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<Real>);
TCompareFunctorDouble =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<Double>);
TCompareFunctorExtended =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<Extended>);
TCompareFunctorCurrency =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<Currency>);
TCompareFunctorBoolean =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<Boolean>);
TCompareFunctorChar =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<Char>);
TCompareFunctorWideChar =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<WideChar>);
TCompareFunctorAnsiString =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<AnsiString>);
TCompareFunctorString =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<String>);
TCompareFunctorWideString =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultCompareFunctor<WideString>);
{ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Unsortable Compare functor
Functor which can use to unsortable elements.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= }
{$IFDEF FPC}generic{$ENDIF} TUnsortableFunctor<V> = class
({$IFDEF FPC}specialize{$ENDIF} TBinaryFunctor<V, Integer>)
public
function Call({%H-}AValue1, {%H-}AValue2 : V) : Integer; override;
end;
{ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Less logic functor
Return True if AValue1 < AValue2.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= }
{$IFDEF FPC}generic{$ENDIF} TDefaultLessFunctor<V> =
class ({$IFDEF FPC}specialize{$ENDIF} TBinaryFunctor<V, Boolean>)
public
function Call(AValue1, AValue2 : V) : Boolean; override;
end;
{ Functors for default types. }
TLessFunctorByte =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<Byte>);
TLessFunctorShortInt =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<ShortInt>);
TLessFunctorWord =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<Word>);
TLessFunctorSmallInt =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<SmallInt>);
TLessFunctorInteger =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<Integer>);
{$IFDEF FPC}
TLessFunctorDWord =
class(specialize TDefaultLessFunctor<DWord>);
{$ENDIF}
TLessFunctorCardinal =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<Cardinal>);
TLessFunctorLongWord =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<LongWord>);
TLessFunctorLongInt =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<LongInt>);
{$IFDEF FPC}
TLessFunctorQWord =
class(specialize TDefaultLessFunctor<QWord>);
{$ENDIF}
TLessFunctorInt64 =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<Int64>);
TLessFunctorSingle =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<Single>);
TLessFunctorReal =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<Real>);
TLessFunctorDouble =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<Double>);
TLessFunctorExtended =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<Extended>);
TLessFunctorCurrency =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<Currency>);
TLessFunctorBoolean =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<Boolean>);
TLessFunctorChar =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<Char>);
TLessFunctorWideChar =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<WideChar>);
TLessFunctorAnsiString =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<AnsiString>);
TLessFunctorString =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<String>);
TLessFunctorWideString =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultLessFunctor<WideString>);
{ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Greater logic functor
Return True if AValue1 > AValue2.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= }
{$IFDEF FPC}generic{$ENDIF} TDefaultGreaterFunctor<V> =
class ({$IFDEF FPC}specialize{$ENDIF} TBinaryFunctor<V, Boolean>)
public
function Call(AValue1, AValue2 : V) : Boolean; override;
end;
{ Functors for default types. }
TGreaterFunctorByte =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<Byte>);
TGreaterFunctorShortInt =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<ShortInt>);
TGreaterFunctorWord =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<Word>);
TGreaterFunctorSmallInt =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<SmallInt>);
TGreaterFunctorInteger =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<Integer>);
{$IFDEF FPC}
TGreaterFunctorDWord =
class(specialize TDefaultGreaterFunctor<DWord>);
{$ENDIF}
TGreaterFunctorCardinal =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<Cardinal>);
TGreaterFunctorLongWord =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<LongWord>);
TGreaterFunctorLongInt =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<LongInt>);
{$IFDEF FPC}
TGreaterFunctorQWord =
class(specialize TDefaultGreaterFunctor<QWord>);
{$ENDIF}
TGreaterFunctorInt64 =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<Int64>);
TGreaterFunctorSingle =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<Single>);
TGreaterFunctorReal =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<Real>);
TGreaterFunctorDouble =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<Double>);
TGreaterFunctorExtended =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<Extended>);
TGreaterFunctorCurrency =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<Currency>);
TGreaterFunctorBoolean =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<Boolean>);
TGreaterFunctorChar =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<Char>);
TGreaterFunctorWideChar =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<WideChar>);
TGreaterFunctorAnsiString =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<AnsiString>);
TGreaterFunctorString =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<String>);
TGreaterFunctorWideString =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultGreaterFunctor<WideString>);
{ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Equal logic functor
Return True if AValue1 = AValue2.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= }
{$IFDEF FPC}generic{$ENDIF} TDefaultEqualFunctor<V> =
class ({$IFDEF FPC}specialize{$ENDIF} TBinaryFunctor<V, Boolean>)
public
function Call(AValue1, AValue2 : V) : Boolean; override;
end;
{ Functors for default types. }
TEqualFunctorByte =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<Byte>);
TEqualFunctorShortInt =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<ShortInt>);
TEqualFunctorWord =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<Word>);
TEqualFunctorSmallInt =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<SmallInt>);
TEqualFunctorInteger =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<Integer>);
{$IFDEF FPC}
TEqualFunctorDWord =
class(specialize TDefaultEqualFunctor<DWord>);
{$ENDIF}
TEqualFunctorCardinal =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<Cardinal>);
TEqualFunctorLongWord =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<LongWord>);
TEqualFunctorLongInt =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<LongInt>);
{$IFDEF FPC}
TEqualFunctorQWord =
class(specialize TDefaultEqualFunctor<QWord>);
{$ENDIF}
TEqualFunctorInt64 =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<Int64>);
TEqualFunctorSingle =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<Single>);
TEqualFunctorReal =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<Real>);
TEqualFunctorDouble =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<Double>);
TEqualFunctorExtended =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<Extended>);
TEqualFunctorCurrency =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<Currency>);
TEqualFunctorBoolean =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<Boolean>);
TEqualFunctorChar =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<Char>);
TEqualFunctorWideChar =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<WideChar>);
TEqualFunctorAnsiString =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<AnsiString>);
TEqualFunctorString =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<String>);
TEqualFunctorWideString =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultEqualFunctor<WideString>);
{ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Pair key compare functor
Return a negative value if pair 1 key value should be sorted before pair 2
key value, a positive value if pair 1 key value should be sorted after
pair 2 key value, zero if pair 1 key value and pair 2 key value 2 are equal.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= }
{$IFDEF FPC}generic{$ENDIF} TDefaultPairKeyCompareFunctor<K, V> =
class({$IFDEF FPC}specialize{$ENDIF} TBinaryFunctor
<{$IFDEF FPC}specialize{$ENDIF} TPair<K, V>, Integer>)
public
function Call (AValue1, AValue2 : {$IFDEF FPC}specialize{$ENDIF} TPair<K,
V>) : Integer; override;
end;
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorByte<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<Byte,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorShortInt<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<ShortInt,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorWord<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<Word,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorSmallInt<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<SmallInt,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorInteger<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<Integer,
V>);
{$IFDEF FPC}
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorDWord<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<DWord,
V>);
{$ENDIF}
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorCardinal<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<Cardinal,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorLongWord<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<LongWord,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorLongInt<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<LongInt,
V>);
{$IFDEF FPC}
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorQWord<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<QWord,
V>);
{$ENDIF}
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorInt64<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<Int64,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorSingle<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<Single,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorReal<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<Real,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorDouble<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<Double,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorExtended<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<Extended,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorCurrency<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<Currency,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorBoolean<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<Boolean,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorChar<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<Char,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorWideChar<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<WideChar,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorAnsiString<V> =
class({$IFDEF FPC}specialize{$ENDIF}
TDefaultPairKeyCompareFunctor<AnsiString, V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorString<V> =
class({$IFDEF FPC}specialize{$ENDIF} TDefaultPairKeyCompareFunctor<String,
V>);
{$IFDEF FPC}generic{$ENDIF} TPairKeyCompareFunctorWideString<V> =
class({$IFDEF FPC}specialize{$ENDIF}
TDefaultPairKeyCompareFunctor<WideString, V>);
implementation
function TDefaultCompareFunctor{$IFNDEF FPC}<V>{$ENDIF}
.Call(AValue1, AValue2 : V) : Integer;
begin
{$IFNDEF FPC}
Result := TComparer<V>.Default.Compare(AValue1, AValue2);
{$ELSE}
if AValue1 < AValue2 then
begin
Result := -1;
end else if AValue2 < AValue1 then
begin
Result := 1
end else
begin
Result := 0;
end;
{$ENDIF}
end;
function TUnsortableFunctor{$IFNDEF FPC}<V>{$ENDIF}
.Call (AValue1, AValue2 : V) : Integer;
begin
Result := 0;
end;
function TDefaultLessFunctor{$IFNDEF FPC}<V>{$ENDIF}
.Call(AValue1, AValue2 : V) : Boolean;
begin
{$IFNDEF FPC}
Result := TComparer<V>.Default.Compare(AValue1, AValue2) < 1;
{$ELSE}
Result := AValue1 < AValue2;
{$ENDIF}
end;
function TDefaultGreaterFunctor{$IFNDEF FPC}<V>{$ENDIF}
.Call(AValue1, AValue2 : V) : Boolean;
begin
{$IFNDEF FPC}
Result := TComparer<V>.Default.Compare(AValue1, AValue2) > 1;
{$ELSE}
Result := AValue1 > AValue2;
{$ENDIF}
end;
function TDefaultEqualFunctor{$IFNDEF FPC}<V>{$ENDIF}
.Call(AValue1, AValue2 : V) : Boolean;
begin
{$IFNDEF FPC}
Result := TComparer<V>.Default.Compare(AValue1, AValue2) = 0;
{$ELSE}
Result := AValue1 = AValue2;
{$ENDIF}
end;
function TDefaultPairKeyCompareFunctor{$IFNDEF FPC}<K, V>{$ENDIF}
.Call(AValue1, AValue2 : {$IFDEF FPC}specialize{$ENDIF} TPair<K, V>) :
Integer;
begin
{$IFNDEF FPC}
Result := TComparer<K>.Default.Compare(AValue1.First, AValue2.First);
{$ELSE}
if AValue1.First < AValue2.First then
begin
Result := -1;
end else if AValue2.First < AValue1.First then
begin
Result := 1
end else
begin
Result := 0;
end;
{$ENDIF}
end;
end.