Skip to content

Commit 9de74c4

Browse files
authored
Merge pull request #4152 from WalterBright/hasMoveCtor
Add __traits(hasMoveConstructor, type)
2 parents d74f363 + 2c5b050 commit 9de74c4

File tree

1 file changed

+47
-9
lines changed

1 file changed

+47
-9
lines changed

spec/traits.dd

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ $(GNAME TraitsKeyword):
5151
$(RELATIVE_LINK2 isPackage, $(D isPackage))
5252
$(RELATIVE_LINK2 hasMember, $(D hasMember))
5353
$(RELATIVE_LINK2 hasCopyConstructor, $(D hasCopyConstructor))
54+
$(RELATIVE_LINK2 hasMoveConstructor, $(D hasMoveConstructor))
5455
$(RELATIVE_LINK2 hasPostblit, $(D hasPostblit))
5556
$(RELATIVE_LINK2 identifier, $(D identifier))
5657
$(RELATIVE_LINK2 fullyQualifiedName, $(D fullyQualifiedName))
@@ -408,30 +409,28 @@ static assert(__traits(isZeroInit, void));
408409

409410
$(H3 $(GNAME hasCopyConstructor))
410411

411-
$(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.
412+
$(P The argument is a type.
413+
If it is a struct with a copy constructor, returns $(D true). Otherwise, return $(D false).
414+
A copy constructor is distinct from a move constructor or a postblit.
412415
)
413416

414417
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
415418
---
416419

417420
import std.stdio;
418421

419-
struct S
420-
{
421-
}
422+
struct S { }
422423

423-
class C
424-
{
425-
}
424+
class C { }
426425

427426
struct P
428427
{
429-
this(ref P rhs) {}
428+
this(ref P rhs) {} // copy constructor
430429
}
431430

432431
struct B
433432
{
434-
this(this) {}
433+
this(this) {} // postblit
435434
}
436435

437436
void main()
@@ -444,6 +443,45 @@ void main()
444443
---
445444
)
446445

446+
$(H3 $(GNAME hasMoveConstructor))
447+
448+
$(P The argument is a type.
449+
If it is a struct with a move constructor, returns $(D true). Otherwise, return $(D false).
450+
A move constructor is distinct from a copy constructor or a postblit.
451+
)
452+
453+
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
454+
---
455+
456+
import std.stdio;
457+
458+
struct S
459+
{
460+
this(S rhs) {} // move constructor
461+
}
462+
463+
class C { }
464+
465+
struct P
466+
{
467+
this(ref P rhs) {} // copy constructor
468+
}
469+
470+
struct B
471+
{
472+
this(this) {} // postblit
473+
}
474+
475+
void main()
476+
{
477+
writeln(__traits(hasMoveConstructor, S)); // true
478+
writeln(__traits(hasMoveConstructor, C)); // false
479+
writeln(__traits(hasMoveConstructor, P)); // false
480+
writeln(__traits(hasMoveConstructor, B)); // false, this is a postblit
481+
}
482+
---
483+
)
484+
447485
$(H3 $(GNAME hasPostblit))
448486

449487
$(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.

0 commit comments

Comments
 (0)