Pure Factory Functions 💔 `inout`

ag0aep6g anonymous at example.com
Fri Feb 10 14:37:35 UTC 2023


On Friday, 10 February 2023 at 14:00:20 UTC, Steven Schveighoffer 
wrote:
> It can be weakly pure. The docs are wrong.
>
> i.e. this works:
>
> ```d
> pure int *foo(const int *p)
> {
>    return new int(5);
> }
>
> void main()
> {
>    int x;
>    immutable int * bar = foo(&x);
> }
> ```

That function "has no parameters with mutable indirections". So 
it's strongly pure, not weakly pure.

I'd guess that `inout` counts like `const` with regards to 
weak/strong purity. So a `pure` function with `inout` parameters 
is also strongly pure.


More information about the Digitalmars-d mailing list