"Fossies" - the Fresh Open Source Software Archive

Member "dmd-2.089.1/test/compilable/test19203.d" (14 Dec 2019, 540 Bytes) of package /linux/misc/dmd-2.089.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) D source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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 }
   27