Issue with const

2012-04-09 Thread Jacob Carlborg
Say I have type and a function look like this: class Foo { void* data; Foo clone () { auto c = new Foo; c.data = data; return c; } } void bar (Foo foo) { auto c = foo.clone(); ... } Since I'm not changing anything on foo I thought that it could

Re: Issue with const

2012-04-09 Thread Timon Gehr
On 04/09/2012 04:49 PM, Jacob Carlborg wrote: But now when I compile this code I get this error: Error: cannot implicitly convert expression (this.data) of type const(void*) to void* Any idea how to solve this? Or would I need to drop const. -- /Jacob Carlborg Either clone the data too or

Re: Issue with const

2012-04-09 Thread Jacob Carlborg
On 2012-04-09 17:30, Steven Schveighoffer wrote: // untested inout(Foo) clone() inout { return new inout(Foo)(data); } Note, you can't post-assign data, since inout is effectively const inside an inout function. -Steve Ok, that works. But then I want to modify the clone: void bar (const

Re: Issue with const

2012-04-09 Thread Steven Schveighoffer
On Mon, 09 Apr 2012 13:51:17 -0400, Jacob Carlborg d...@me.com wrote: On 2012-04-09 17:30, Steven Schveighoffer wrote: // untested inout(Foo) clone() inout { return new inout(Foo)(data); } Note, you can't post-assign data, since inout is effectively const inside an inout function. -Steve

Re: Issue with const

2012-04-09 Thread Jonathan M Davis
On Monday, April 09, 2012 19:51:17 Jacob Carlborg wrote: On 2012-04-09 17:30, Steven Schveighoffer wrote: // untested inout(Foo) clone() inout { return new inout(Foo)(data); } Note, you can't post-assign data, since inout is effectively const inside an inout function. -Steve

Re: Issue with const

2012-04-09 Thread Jacob Carlborg
On 2012-04-09 19:56, Steven Schveighoffer wrote: Then c.data cannot be the same reference as foo.data. Counter-case: void bar( const Foo foo) { auto c = foo.clone(); // assume this works; *(cast(int*)c.data) = 6; // note even though I'm casting, there is no removal of const, so this should be