mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 06:00:35 +03:00
Merge pull request #6324 from JackStouffer/traits-examples2
Added examples, improved docs, and changed style of std.traits.QualifierOf merged-on-behalf-of: Jack Stouffer <jack@jackstouffer.com>
This commit is contained in:
commit
4ac4a06ace
1 changed files with 32 additions and 8 deletions
40
std/traits.d
40
std/traits.d
|
@ -421,16 +421,40 @@ template ImmutableOf(T)
|
||||||
static assert(is( ImmutableOf!int == immutable int));
|
static assert(is( ImmutableOf!int == immutable int));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get qualifier template from the given type T
|
/**
|
||||||
|
* Gives a template that can be used to apply the same
|
||||||
|
* attributes that are on the given type `T`. E.g. passing
|
||||||
|
* `inout shared int` will return `SharedInoutOf`.
|
||||||
|
*
|
||||||
|
* Params:
|
||||||
|
* T = the type to check qualifiers from
|
||||||
|
* Returns:
|
||||||
|
* The qualifier template from the given type `T`
|
||||||
|
*/
|
||||||
template QualifierOf(T)
|
template QualifierOf(T)
|
||||||
{
|
{
|
||||||
static if (is(T == shared(const U), U)) alias QualifierOf = SharedConstOf;
|
static if (is(T == shared(const U), U))
|
||||||
else static if (is(T == const U , U)) alias QualifierOf = ConstOf;
|
alias QualifierOf = SharedConstOf;
|
||||||
else static if (is(T == shared(inout U), U)) alias QualifierOf = SharedInoutOf;
|
else static if (is(T == const U, U))
|
||||||
else static if (is(T == inout U , U)) alias QualifierOf = InoutOf;
|
alias QualifierOf = ConstOf;
|
||||||
else static if (is(T == immutable U , U)) alias QualifierOf = ImmutableOf;
|
else static if (is(T == shared(inout U), U))
|
||||||
else static if (is(T == shared U , U)) alias QualifierOf = SharedOf;
|
alias QualifierOf = SharedInoutOf;
|
||||||
else alias QualifierOf = MutableOf;
|
else static if (is(T == inout U, U))
|
||||||
|
alias QualifierOf = InoutOf;
|
||||||
|
else static if (is(T == immutable U, U))
|
||||||
|
alias QualifierOf = ImmutableOf;
|
||||||
|
else static if (is(T == shared U, U))
|
||||||
|
alias QualifierOf = SharedOf;
|
||||||
|
else
|
||||||
|
alias QualifierOf = MutableOf;
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
@safe unittest
|
||||||
|
{
|
||||||
|
static assert(__traits(isSame, QualifierOf!(immutable int), ImmutableOf));
|
||||||
|
static assert(__traits(isSame, QualifierOf!(shared int), SharedOf));
|
||||||
|
static assert(__traits(isSame, QualifierOf!(shared inout int), SharedInoutOf));
|
||||||
}
|
}
|
||||||
|
|
||||||
@safe unittest
|
@safe unittest
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue