Skip to content

Commit ecd3c91

Browse files
chibisiBolpat
authored andcommitted
Update traits.dd
Added template alias example to isSame trait
1 parent 992eb48 commit ecd3c91

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

spec/traits.dd

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,30 @@ static assert(__traits(isSame, object, object));
19301930
alias daz = foo;
19311931
static assert(__traits(isSame, foo, daz));
19321932
---
1933+
)
1934+
$(P isSame will also match template symbols as well as types.)
1935+
1936+
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
1937+
---
1938+
struct Foo(T){
1939+
T x;
1940+
}
1941+
1942+
struct Bar(T){
1943+
T x;
1944+
}
1945+
1946+
struct Point(T){
1947+
T x;
1948+
T y;
1949+
}
1950+
1951+
enum isFooOrBar(alias FB) = __traits(isSame, FB, Foo) || __traits(isSame, FB, Bar);
1952+
1953+
static assert(isFooOrBar!(Foo));//true
1954+
static assert(isFooOrBar!(Bar));//true
1955+
static assert(isFooOrBar!(Point));//false
1956+
---
19331957
)
19341958

19351959
$(P The result is `true` if the two arguments are expressions

0 commit comments

Comments
 (0)