Hello D people,
I stumbled upon a weird thing which I don't find in the language documentation. The compiler allows me to define enum functions
with enum
keyword instead of auto
keyword. It gets more weird. It seems like being an actual auto
function with the only difference that it doesn't allow const
or immutable
but inout
qualifier in enum
-methods.
struct S {
enum barz(int x) { // fine
return x;
}
enum foo(int x) inout { // fine
return x;
}
// can't use 'enum' with those
auto foox(int x) const inout {
return x;
}
auto bar(int x) const {
return x;
}
auto baz(int x) immutable {
return x;
}
}
I'd like to know:
-
What does return type
enum
mean?It's definitely not compile-time-static here and it's definitely not required to be assigned to an enum (
auto
works as well). -
What is the difference to using
auto
as return value ? -
Why is there no shortform template syntax for enums? I have to write it like this:
template MyEnum(X) {
enum MyEnum {
a = X,
b, c, d
}
}
Regards!