-
Notifications
You must be signed in to change notification settings - Fork 0
/
U_pair.pas
78 lines (61 loc) · 1.86 KB
/
U_pair.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
unit U_pair;
interface
uses System.Generics.Collections; // ßþÞ
type
ß<T> = record
Key, Value: T;
constructor Create(const K,V: T);
function ToString : string;
class operator implicit (p:TPair<T,T>) : ß<T>;
class operator implicit (p:ß<T>) : TPair<T,T>;
end;
þ_int = ß<integer>; //TPair<integer,integer>;
þ_str = ß<string>; //TPair<string,string>;
tp = record
class function þ<T>(a,b:T) : ß<T>; static;
end;
function þ(a,b:integer) : þ_int; {TPair<integer,integer>;} overload;
function þ(a,b:string) : þ_str; {TPair<string,string>;} overload;
implementation
uses System.Rtti, System.SysUtils;
class function tp.þ<T>(a,b:T) : ß<T>;
begin
result := ß<T>.Create(a,b);
end;
function þ(a,b:integer) : þ_int; {TPair<integer,integer>;} overload;
begin
result := tp.þ(a,b);
end;
function þ(a,b:string) : þ_str; {TPair<string,string>;} overload;
begin
result := tp.þ(a,b);
end;
constructor ß<T>.Create(const K,V: T);
begin
Key := K; Value := V;
end;
class operator ß<T>.implicit (p:TPair<T,T>) : ß<T>;
begin
result.Create(p.Key,p.Value);
end;
class operator ß<T>.implicit (p:ß<T>) : TPair<T,T>;
begin
result.Create(p.Key,p.Value);
end;
function ß<T>.ToString : string;
begin
case GetTypeKind(T) of
tkInteger : result := '(' + TValue.From<T>(Key) .ToString + ', '
+ TValue.From<T>(Value).ToString + ')';
tkChar,
tkWChar,
tkString,
tkUString,
tkLString,
tkWString : result := '("' + TValue.From<T>(Key) .ToString + '", "'
+ TValue.From<T>(Value).ToString + '")';
else
result := 'x ' + TValue.From<TTypeKind>( GetTypeKind(T) ).ToString;
end;
end;
end.