Problem with const correctness

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Fri Dec 7 06:18:30 PST 2012


Consider this example:

struct Array(Type_)
{
public:
this(Type_ array_[]...)
{
_array = array_;
}
 this(this)
{
_array = _array.dup;
}
 ref Array!Type_ opAssign(in Array!Type_ array_)
{
_array = array_._array.dup;
return this;
}
 private:
Type_[] _array;
}
 unittest
{
Array!int one = Array!int(1, 2, 3, 4, 5);
immutable Array!int two = one; //Error: conversion error from Array!(int)
to immutable(Array!(int))
}
I enforce value-type semantics by duplicating the arrays on copy, so it
should behave like a value type with no indirections (implicitly convert to
immutable).
What do I need to do for this to work?

-- 
Bye,
Gor Gyolchanyan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20121207/b80b337b/attachment.html>


More information about the Digitalmars-d mailing list