Skip to content

Commit 45ce9be

Browse files
authored
Merge pull request #2715 from adamdruppe/css
document hasCopyConstructor and hasPostblit traits merged-on-behalf-of: Petar Kirov <[email protected]>
2 parents 6fccf0f + 2afbcd6 commit 45ce9be

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

spec/traits.dd

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ $(GNAME TraitsKeyword):
4747
$(GLINK isModule)
4848
$(GLINK isPackage)
4949
$(GLINK hasMember)
50+
$(GLINK hasCopyConstructor)
51+
$(GLINK hasPostblit)
5052
$(GLINK identifier)
5153
$(GLINK getAliasThis)
5254
$(GLINK getAttributes)
@@ -664,6 +666,83 @@ void main()
664666
---
665667
)
666668

669+
$(H2 $(GNAME hasCopyConstructor))
670+
671+
$(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.
672+
)
673+
674+
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
675+
---
676+
677+
import std.stdio;
678+
679+
struct S
680+
{
681+
}
682+
683+
class C
684+
{
685+
}
686+
687+
struct P
688+
{
689+
this(ref P rhs) {}
690+
}
691+
692+
struct B
693+
{
694+
this(this) {}
695+
}
696+
697+
void main()
698+
{
699+
writeln(__traits(hasCopyConstructor, S)); // false
700+
writeln(__traits(hasCopyConstructor, C)); // false
701+
writeln(__traits(hasCopyConstructor, P)); // true
702+
writeln(__traits(hasCopyConstructor, B)); // false, this is a postblit
703+
}
704+
---
705+
)
706+
707+
$(H2 $(GNAME hasPostblit))
708+
709+
$(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.
710+
)
711+
712+
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
713+
---
714+
715+
import std.stdio;
716+
717+
struct S
718+
{
719+
}
720+
721+
class C
722+
{
723+
}
724+
725+
struct P
726+
{
727+
this(ref P rhs) {}
728+
}
729+
730+
struct B
731+
{
732+
this(this) {}
733+
}
734+
735+
736+
void main()
737+
{
738+
writeln(__traits(hasPostblit, S)); // false
739+
writeln(__traits(hasPostblit, C)); // false
740+
writeln(__traits(hasPostblit, P)); // false, this is a copy ctor
741+
writeln(__traits(hasPostblit, B)); // true
742+
}
743+
---
744+
)
745+
667746
$(H2 $(GNAME identifier))
668747

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

0 commit comments

Comments
 (0)