Debian Codegraph @

gcc/testsuite/gdc.test/compilable/test19203.d

raw
1 //https://issues.dlang.org/show_bug.cgi?id=19203
2 struct BoolWithErr {
3 bool b;
4 string error;
5 alias b this;
6 }
7
8 struct Foo {
9 int popBack() { return 0; }
10 }
11
12 struct Bar {}
13
14 template hasPopBack(T) {
15 static if (!is(typeof(T.init.popBack)))
16 enum hasPopBack = BoolWithErr(false, T.stringof~" does not have popBack");
17 else
18 enum hasPopBack = BoolWithErr(true,"");
19 }
20
21 void test()
22 {
23 static assert( hasPopBack!Foo);
24 static assert(!hasPopBack!Bar);
25 static assert( hasPopBack!Foo && !hasPopBack!Bar);
26 }