View source code
Display the source code in std/traits.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Enum member std.traits.isNarrowString

Detect whether type T is a narrow string.

enum isNarrowString(T) = is(immutable(T) == immutable(C[]), C) && (is(C == char) || is(C == wchar));

All arrays that use char, wchar, and their qualified versions are narrow strings. (Those include string and wstring).

Example

static assert(isNarrowString!string);
static assert(isNarrowString!wstring);
static assert(isNarrowString!(char[]));
static assert(isNarrowString!(wchar[]));

static assert(!isNarrowString!dstring);
static assert(!isNarrowString!(dchar[]));

static assert(!isNarrowString!(typeof(null)));
static assert(!isNarrowString!(char[4]));

enum ES : string { a = "aaa", b = "bbb" }
static assert(!isNarrowString!ES);

static struct Stringish
{
    string str;
    alias str this;
}
static assert(!isNarrowString!Stringish);

Authors

Walter Bright, Tomasz Stachowiak (isExpressions), Andrei Alexandrescu, Shin Fujishiro, Robert Clipsham, David Nadlinger, Kenji Hara, Shoichi Kato

License

Boost License 1.0.