How can overloads be distinguished on attributes alone?
Quirin Schroll
qs.il.paperinik at gmail.com
Mon Jul 31 10:55:44 UTC 2023
Apparently, functions can be overloaded solely distinguished by
attributes:
```d
void f(ref int x) pure { x = 1; }
void f(ref int x) { x = 2; static int s; ++s; }
```
I thought that, maybe, a `pure` context calls the `pure` function
and an impure context calls the impure function, but no: Calling
`f` leads to an ambiguity error in both contexts. Even if that
worked, what about inferred contexts, i.e. templates? In simple
cases, they could forward the contexts in which they are called,
but you can instantiate a template without calling it.
What am I missing here?
More information about the Digitalmars-d-learn
mailing list