Possible 'pure' bug with int[] slice. Programming in D page 174
Steven Schveighoffer
schveiguy at gmail.com
Wed Oct 8 15:55:28 UTC 2025
On Wednesday, 8 October 2025 at 08:48:12 UTC, Kagamin wrote:
> To be pedantic, strong purity requires immutable arguments,
> const are not enough:
> ```
> void main()
> {
> import std.stdio : writeln;
>
> int[] numbers = [5, 6, 7, 8, 9];
> writeln("numbers before: ", id(numbers));
> numbers[0]=1;
> writeln("numbers after : ", id(numbers));
> }
>
> const(int)[] id(const int[] p) pure
> {
> return p;
> }
> ```
Yes, thank you for the correction.
I got this confused with pure factory functions, where returning
a mutable item from const parameters allows the compiler to
assume the return value is unique.
-Steve
More information about the Digitalmars-d-learn
mailing list