View difference between Paste ID: f2FUAYQT and CG1VZs8W
SHOW: | | - or go back to the newest paste.
1-
import std;
1+
2
/++
3-
void main()
3+
4
 +  unqualified elements.
5-
    writeln("Hello D");
5+
6
 +  Params:
7
 +      QualArray = Qualified array type.
8
 +      QualType = Qualified type, element of `QualArray`.
9
 +/
10
template UnqualArray(QualArray : QualType[], QualType)
11
if (!isAssociativeArray!QualType)
12
{
13
    alias UnqualArray = Unqual!QualType[];
14
}
15
16
///
17
unittest
18
{
19
    alias ConstStrings = const(string)[];
20
    alias UnqualStrings = UnqualArray!ConstStrings;
21
    static assert(is(UnqualStrings == string[]));
22
23
    alias ImmChars = string;
24
    alias UnqualChars = UnqualArray!ImmChars;
25
    static assert(is(UnqualChars == char[]));
26
27
    alias InoutBools = inout(bool)[];
28
    alias UnqualBools = UnqualArray!InoutBools;
29
    static assert(is(UnqualBools == bool[]));
30
31
    alias ConstChars = const(char)[];
32
    alias UnqualChars2 = UnqualArray!ConstChars;
33
    static assert(is(UnqualChars2 == char[]));
34
}
35
36
37
// UnqualArray
38
/++
39
 +  Given an associative array with elements that have a storage class, aliases
40
 +  itself to an associative array with elements without the storage classes.
41
 +
42
 +  Params:
43
 +      QualArray = Qualified associative array type.
44
 +      QualElem = Qualified type, element of `QualArray`.
45
 +      QualKey = Qualified type, key of `QualArray`.
46
 +/
47
template UnqualArray(QualArray : QualElem[QualKey], QualElem, QualKey)
48
if (!isArray!QualElem)
49
{
50
    alias UnqualArray = Unqual!QualElem[Unqual!QualKey];
51
}
52
53
///
54
unittest
55
{
56
    alias ConstStringAA = const(string)[int];
57
    alias UnqualStringAA = UnqualArray!ConstStringAA;
58
    static assert (is(UnqualStringAA == string[int]));
59
60
    alias ImmIntAA = immutable(int)[char];
61
    alias UnqualIntAA = UnqualArray!ImmIntAA;
62
    static assert(is(UnqualIntAA == int[char]));
63
64
    alias InoutBoolAA = inout(bool)[long];
65
    alias UnqualBoolAA = UnqualArray!InoutBoolAA;
66
    static assert(is(UnqualBoolAA == bool[long]));
67
68
    alias ConstCharAA = const(char)[string];
69
    alias UnqualCharAA = UnqualArray!ConstCharAA;
70
    static assert(is(UnqualCharAA == char[string]));
71
}
72
73
74
// UnqualArray
75
/++
76
 +  Given an associative array of arrays with a storage class, aliases itself to
77
 +  an associative array with array elements without the storage classes.
78
 +
79
 +  Params:
80
 +      QualArray = Qualified associative array type.
81
 +      QualElem = Qualified type, element of `QualArray`.
82
 +      QualKey = Qualified type, key of `QualArray`.
83
 +/
84
template UnqualArray(QualArray : QualElem[QualKey], QualElem, QualKey)
85
if (isArray!QualElem)
86
{
87
    static if (isTrulyString!(Unqual!QualElem))
88
    {
89
        alias UnqualArray = Unqual!QualElem[Unqual!QualKey];
90
    }
91
    else
92
    {
93
        alias UnqualArray = UnqualArray!QualElem[Unqual!QualKey];
94
    }
95
}
96
97
///
98
unittest
99
{
100
    alias ConstStringArrays = const(string[])[int];
101
    alias UnqualStringArrays = UnqualArray!ConstStringArrays;
102
    static assert (is(UnqualStringArrays == string[][int]));
103
104
    alias ImmIntArrays = immutable(int[])[char];
105
    alias UnqualIntArrays = UnqualArray!ImmIntArrays;
106
    static assert(is(UnqualIntArrays == int[][char]));
107
108
    alias InoutBoolArrays = inout(bool)[][long];
109
    alias UnqualBoolArrays = UnqualArray!InoutBoolArrays;
110
    static assert(is(UnqualBoolArrays == bool[][long]));
111
112
    alias ConstCharArrays = const(char)[][string];
113
    alias UnqualCharArrays = UnqualArray!ConstCharArrays;
114
    static assert(is(UnqualCharArrays == char[][string]));
115
}
116
117
118
// isTrulyString
119
/++
120
 +  True if a type is `string`, `dstring` or `wstring`; otherwise false.
121
 +
122
 +  Does not consider e.g. `char[]` a string, as `std.traits.isSomeString` does.
123
 +
124
 +  Params:
125
 +      S = String type to introspect.
126
 +/
127
enum isTrulyString(S) = is(S == string) || is(S == dstring) || is(S == wstring);
128
129
///
130
unittest
131
{
132
    static assert(isTrulyString!string);
133
    static assert(isTrulyString!dstring);
134
    static assert(isTrulyString!wstring);
135
    static assert(!isTrulyString!(char[]));
136
    static assert(!isTrulyString!(dchar[]));
137
    static assert(!isTrulyString!(wchar[]));
138
}