Overloading based on attributes - is it a good idea?
Exil
Exil at gmall.com
Sat Jun 1 12:08:50 UTC 2019
Found some odd behavior, seems if a template needs to reference
itself, it does not add the @nogc attribute to itself. Meaning
it's type is not @nogc/nothrow, but it can still be called in
@nogc functions. Unless you take a pointer to it, then it doesn't
have the attributes so it can't be called.
https://run.dlang.io/is/YJDs7y
import std.stdio;
void test3(t)() {
import core.stdc.stdio;
printf("%s\n", t.stringof.ptr);
}
void test2(bool check)() {
static if(check) test3!(typeof(&test2))();
else test3!(int)();
}
void main() @nogc {
auto p1 = &test2!false;
auto p2 = &test2!true;
test2!false();
p1();
test2!true(); // ok
// p2(); // error can't call @nogc function
printf("---\n%s\n%s\n", typeof(p1).stringof.ptr,
typeof(p2).stringof.ptr);
}
More information about the Digitalmars-d
mailing list