enum functions

Salih Dincer salihdb at hotmail.com
Sun Jan 8 18:42:58 UTC 2023


Aho,

I accidentally had a function like this:

```d
     enum oneHalf(T)(T i) {
         return i >> 1;
     }
```

I'm wondering 2 things; firstly, does having an enum mean there 
is no auto-return? Or could it be CTFE?

Second, why is there no inference when I use an enum in one of 
the functions below?

```d
template foo (T) {
     enum foo = (T i) => i >> 1;
}

template bar (T) {
     auto bar (T i) => i >> 1;
}

import std;

void main()
{
     assert(oneHalf(42) == 21);
     42.foo!int.writeln; // no inference: "21"
     42.bar.writeln; // "21"
}
```

Thanks...

SDB at 79


More information about the Digitalmars-d-learn mailing list