Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions spec/traits.dd
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ $(GNAME TraitsKeyword):
$(GLINK isModule)
$(GLINK isPackage)
$(GLINK hasMember)
$(GLINK hasCopyConstructor)
$(GLINK hasPostblit)
$(GLINK identifier)
$(GLINK getAliasThis)
$(GLINK getAttributes)
Expand Down Expand Up @@ -664,6 +666,83 @@ void main()
---
)

$(H2 $(GNAME hasCopyConstructor))

$(P The argument is a type. If it is a struct with a copy constructor, returns $(D true). Otherwise, return $(D false). Note that a copy constructor is distinct from a postblit.
)

$(SPEC_RUNNABLE_EXAMPLE_COMPILE
---

import std.stdio;

struct S
{
}

class C
{
}

struct P
{
this(ref P rhs) {}
}

struct B
{
this(this) {}
}

void main()
{
writeln(__traits(hasCopyConstructor, S)); // false
writeln(__traits(hasCopyConstructor, C)); // false
writeln(__traits(hasCopyConstructor, P)); // true
writeln(__traits(hasCopyConstructor, B)); // false, this is a postblit
}
---
)

$(H2 $(GNAME hasPostblit))

$(P The argument is a type. If it is a struct with a postblit, returns $(D true). Otherwise, return $(D false). Note a postblit is distinct from a copy constructor.
)

$(SPEC_RUNNABLE_EXAMPLE_COMPILE
---

import std.stdio;

struct S
{
}

class C
{
}

struct P
{
this(ref P rhs) {}
}

struct B
{
this(this) {}
}


void main()
{
writeln(__traits(hasPostblit, S)); // false
writeln(__traits(hasPostblit, C)); // false
writeln(__traits(hasPostblit, P)); // false, this is a copy ctor
writeln(__traits(hasPostblit, B)); // true
}
---
)

$(H2 $(GNAME identifier))

$(P Takes one argument, a symbol. Returns the identifier
Expand Down