mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 07:00:37 +03:00
Remove isSomeString and isSomeChar. (#8942)
The consensus seems to be that these two should go, for better or worse.
This commit is contained in:
parent
e16ce73f59
commit
6cbb729db6
1 changed files with 0 additions and 212 deletions
212
lib/sys/traits.d
212
lib/sys/traits.d
|
@ -53,8 +53,6 @@
|
||||||
$(TR $(TD Categories of types) $(TD
|
$(TR $(TD Categories of types) $(TD
|
||||||
$(TR $(TD Traits for removing type qualfiers) $(TD
|
$(TR $(TD Traits for removing type qualfiers) $(TD
|
||||||
$(LREF isDynamicArray)
|
$(LREF isDynamicArray)
|
||||||
$(LREF isSomeChar)
|
|
||||||
$(LREF isSomeString)
|
|
||||||
$(LREF isStaticArray)
|
$(LREF isStaticArray)
|
||||||
))
|
))
|
||||||
$(TR $(TD Traits for removing type qualfiers) $(TD
|
$(TR $(TD Traits for removing type qualfiers) $(TD
|
||||||
|
@ -329,216 +327,6 @@ enum bool isStaticArray(T) = is(T == U[n], U, size_t n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/++
|
|
||||||
Whether the given type is a built-in string type - i.e whether it's a
|
|
||||||
dynamic array of $(D char), $(D wchar), or $(D dchar), ignoring all
|
|
||||||
qualifiers.
|
|
||||||
|
|
||||||
Note that this does not include implicit conversions or enum types. The
|
|
||||||
type itself must be a dynamic array whose element type is one of the three
|
|
||||||
built-in character types.
|
|
||||||
+/
|
|
||||||
enum bool isSomeString(T) = is(immutable T == immutable C[], C) && (is(C == char) || is(C == wchar) || is(C == dchar));
|
|
||||||
|
|
||||||
///
|
|
||||||
@safe unittest
|
|
||||||
{
|
|
||||||
// Some types which are string types.
|
|
||||||
static assert( isSomeString!string);
|
|
||||||
static assert( isSomeString!wstring);
|
|
||||||
static assert( isSomeString!dstring);
|
|
||||||
static assert( isSomeString!(char[]));
|
|
||||||
static assert( isSomeString!(wchar[]));
|
|
||||||
static assert( isSomeString!(dchar[]));
|
|
||||||
static assert( isSomeString!(const char[]));
|
|
||||||
static assert( isSomeString!(immutable char[]));
|
|
||||||
static assert( isSomeString!(inout wchar[]));
|
|
||||||
static assert( isSomeString!(shared wchar[]));
|
|
||||||
static assert( isSomeString!(const shared dchar[]));
|
|
||||||
|
|
||||||
static assert( isSomeString!(typeof("aaa")));
|
|
||||||
static assert( isSomeString!(typeof("aaa"w)));
|
|
||||||
static assert( isSomeString!(typeof("aaa"d)));
|
|
||||||
|
|
||||||
string s;
|
|
||||||
static assert( isSomeString!(typeof(s)));
|
|
||||||
|
|
||||||
// Some types which are not strings.
|
|
||||||
static assert(!isSomeString!int);
|
|
||||||
static assert(!isSomeString!(int[]));
|
|
||||||
static assert(!isSomeString!(byte[]));
|
|
||||||
|
|
||||||
// Static arrays of characters are not considered strings.
|
|
||||||
static assert(!isSomeString!(char[4]));
|
|
||||||
|
|
||||||
static struct S
|
|
||||||
{
|
|
||||||
string str;
|
|
||||||
}
|
|
||||||
static assert(!isSomeString!S);
|
|
||||||
|
|
||||||
// The struct itself isn't considered a string,
|
|
||||||
// but its member variable is when checked directly.
|
|
||||||
static assert( isSomeString!(typeof(S.str)));
|
|
||||||
|
|
||||||
// While strings can be null, typeof(null) is not typed as a string.
|
|
||||||
static assert(!isSomeString!(typeof(null)));
|
|
||||||
|
|
||||||
// However, naturally, if null is cast to a string type,
|
|
||||||
// it's a string type, since the cast forces the type.
|
|
||||||
static assert( isSomeString!(typeof(cast(char[]) null)));
|
|
||||||
|
|
||||||
enum E : string
|
|
||||||
{
|
|
||||||
a = "dlang"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enums do not count.
|
|
||||||
static assert(!isSomeString!E);
|
|
||||||
|
|
||||||
static struct AliasThis
|
|
||||||
{
|
|
||||||
string str;
|
|
||||||
alias this = str;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Other implicit conversions do not count.
|
|
||||||
static assert(!isSomeString!AliasThis);
|
|
||||||
}
|
|
||||||
|
|
||||||
@safe unittest
|
|
||||||
{
|
|
||||||
import lib.sys.meta : Alias, AliasSeq;
|
|
||||||
|
|
||||||
static struct AliasThis(T)
|
|
||||||
{
|
|
||||||
T member;
|
|
||||||
alias this = member;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Q; AliasSeq!(Alias, ConstOf, ImmutableOf, SharedOf))
|
|
||||||
{
|
|
||||||
foreach (T; AliasSeq!(char[], wchar[], dchar[]))
|
|
||||||
{
|
|
||||||
enum E : Q!T { a = Q!T.init }
|
|
||||||
|
|
||||||
static assert( isSomeString!(Q!T));
|
|
||||||
static assert(!isSomeString!E);
|
|
||||||
static assert(!isSomeString!(AliasThis!(Q!T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (T; AliasSeq!(char, wchar, dchar, int, byte[], ubyte[], int[], char[12], wchar[17], dchar[2], void[]))
|
|
||||||
{
|
|
||||||
enum E : Q!T { a = Q!T.init }
|
|
||||||
|
|
||||||
static assert(!isSomeString!(Q!T));
|
|
||||||
static assert(!isSomeString!E);
|
|
||||||
static assert(!isSomeString!(AliasThis!(Q!T)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/++
|
|
||||||
Whether the given type is $(D char), $(D wchar), or $(D dchar), ignoring all
|
|
||||||
qualifiers.
|
|
||||||
|
|
||||||
Note that this does not include implicit conversions or enum types. The
|
|
||||||
type itself must be one of the three built-in character type.
|
|
||||||
+/
|
|
||||||
enum isSomeChar(T) = is(immutable T == immutable char) ||
|
|
||||||
is(immutable T == immutable wchar) ||
|
|
||||||
is(immutable T == immutable dchar);
|
|
||||||
|
|
||||||
///
|
|
||||||
@safe unittest
|
|
||||||
{
|
|
||||||
// Some types which are character types.
|
|
||||||
static assert( isSomeChar!char);
|
|
||||||
static assert( isSomeChar!wchar);
|
|
||||||
static assert( isSomeChar!dchar);
|
|
||||||
static assert( isSomeChar!(const char));
|
|
||||||
static assert( isSomeChar!(immutable char));
|
|
||||||
static assert( isSomeChar!(inout wchar));
|
|
||||||
static assert( isSomeChar!(shared wchar));
|
|
||||||
static assert( isSomeChar!(const shared dchar));
|
|
||||||
|
|
||||||
static assert( isSomeChar!(typeof('c')));
|
|
||||||
static assert( isSomeChar!(typeof("hello world"[3])));
|
|
||||||
|
|
||||||
dchar c;
|
|
||||||
static assert( isSomeChar!(typeof(c)));
|
|
||||||
|
|
||||||
// Some types which aren't character types.
|
|
||||||
static assert(!isSomeChar!int);
|
|
||||||
static assert(!isSomeChar!byte);
|
|
||||||
static assert(!isSomeChar!string);
|
|
||||||
static assert(!isSomeChar!wstring);
|
|
||||||
static assert(!isSomeChar!dstring);
|
|
||||||
static assert(!isSomeChar!(char[4]));
|
|
||||||
|
|
||||||
static struct S
|
|
||||||
{
|
|
||||||
dchar c;
|
|
||||||
}
|
|
||||||
static assert(!isSomeChar!S);
|
|
||||||
|
|
||||||
// The struct itself isn't considered a character,
|
|
||||||
// but its member variable is when checked directly.
|
|
||||||
static assert( isSomeChar!(typeof(S.c)));
|
|
||||||
|
|
||||||
enum E : dchar
|
|
||||||
{
|
|
||||||
a = 'a'
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enums do not count.
|
|
||||||
static assert(!isSomeChar!E);
|
|
||||||
|
|
||||||
static struct AliasThis
|
|
||||||
{
|
|
||||||
dchar c;
|
|
||||||
alias this = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Other implicit conversions do not count.
|
|
||||||
static assert(!isSomeChar!AliasThis);
|
|
||||||
}
|
|
||||||
|
|
||||||
@safe unittest
|
|
||||||
{
|
|
||||||
import lib.sys.meta : Alias, AliasSeq;
|
|
||||||
|
|
||||||
static struct AliasThis(T)
|
|
||||||
{
|
|
||||||
T member;
|
|
||||||
alias this = member;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Q; AliasSeq!(Alias, ConstOf, ImmutableOf, SharedOf))
|
|
||||||
{
|
|
||||||
foreach (T; AliasSeq!(char, wchar, dchar))
|
|
||||||
{
|
|
||||||
enum E : Q!T { a = Q!T.init }
|
|
||||||
|
|
||||||
static assert( isSomeChar!(Q!T));
|
|
||||||
static assert(!isSomeChar!E);
|
|
||||||
static assert(!isSomeChar!(AliasThis!(Q!T)));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (T; AliasSeq!(bool, byte, ubyte, short, ushort, int, uint,
|
|
||||||
long, ulong, float, double, real,
|
|
||||||
char[], wchar[], dchar[], int[], void[],
|
|
||||||
char[12], wchar[17], dchar[2]))
|
|
||||||
{
|
|
||||||
enum E : Q!T { a = Q!T.init }
|
|
||||||
|
|
||||||
static assert(!isSomeChar!(Q!T));
|
|
||||||
static assert(!isSomeChar!E);
|
|
||||||
static assert(!isSomeChar!(AliasThis!(Q!T)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/++
|
/++
|
||||||
Removes the outer layer of $(D const), $(D inout), or $(D immutable)
|
Removes the outer layer of $(D const), $(D inout), or $(D immutable)
|
||||||
from type $(D T).
|
from type $(D T).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue