Overloading based on attributes - is it a good idea?
Kagamin
spam at here.lot
Thu May 30 08:17:17 UTC 2019
On Wednesday, 29 May 2019 at 13:53:37 UTC, Mike Franklin wrote:
> On Tuesday, 28 May 2019 at 16:08:38 UTC, Andrei Alexandrescu
> wrote:
>> int fun(int) pure;
>> int fun(int);
>>
>> pure int gun(int x)
>> {
>> return fun(x);
>> }
>
> I think it really depends on the attribute. I haven't thought
> too much about the other attributes, but for `pure` I don't see
> the use case. If you can make the implementation of `fun(int)`
> pure, why would you need an additional impure implementation?
A use case I found is that the pure overload can use GC to
allocate memory for CTFE, while the impure overload can use a
custom allocator for run time. The compiler always chose pure
overload, so I gave up on purity altogether.
More information about the Digitalmars-d
mailing list