On Sunday, 13 March 2016 at 22:34:54 UTC, Chris Wright wrote:
In theory, it can't be modified. As a practical matter, unions
and casts will allow people to modify it.
Saying that it *can't* be modified is slightly besides the point,
yeah. It *must* not be modified. Casting away const and then
On Sun, 13 Mar 2016 21:14:59 +, anonymous wrote:
> On Sunday, 13 March 2016 at 20:10:57 UTC, Basile B. wrote:
>> ref const(Array!Type) view(){}
>>
>> Unless the result is explicitly cast later it can't me modified.
>
> No, it can't be modified, period. Casting away const and then mutating
>
On Sunday, 13 March 2016 at 20:10:57 UTC, Basile B. wrote:
ref const(Array!Type) view(){}
Unless the result is explicitly cast later it can't me modified.
No, it can't be modified, period. Casting away const and then
mutating is not allowed, it has undefined behavior.
On Sunday, 13 March 2016 at 20:28:33 UTC, JR wrote:
On Sunday, 13 March 2016 at 20:13:03 UTC, Basile B. wrote:
On Sunday, 13 March 2016 at 20:10:57 UTC, Basile B. wrote:
[...]
Basile beat me to it. Yes, ref const(Array!T) accessor.
http://dpaste.dzfl.pl/cb2bc5cf9917
Thank you very much,
On Sunday, 13 March 2016 at 20:13:03 UTC, Basile B. wrote:
On Sunday, 13 March 2016 at 20:10:57 UTC, Basile B. wrote:
[...]
Basile beat me to it. Yes, ref const(Array!T) accessor.
http://dpaste.dzfl.pl/cb2bc5cf9917
On Sunday, 13 March 2016 at 20:10:57 UTC, Basile B. wrote:
Unless the result is explicitly cast later it can't me modified.
import std.stdio, std.container.array;
struct Foo
{
private Array!int arr;
ref const(Array!int) view()
{
return arr;
}
}
void main(string[]
On Sunday, 13 March 2016 at 19:37:42 UTC, ParticlePeter wrote:
I have a struct that privately warps an std.container.array. I
would like to return a read-only reference of this array, it
should not be duplicated. How can I do this?
Cheers, ParticlePeter
ref const(Array!Type) view(){}
I have a struct that privately warps an std.container.array. I
would like to return a read-only reference of this array, it
should not be duplicated. How can I do this?
Cheers, ParticlePeter