Re: const attribute makes whole element const?

2012-09-11 Thread Ali Çehreli
On 09/10/2012 02:49 AM, monarch_dodra wrote: On Sunday, 9 September 2012 at 23:54:45 UTC, Jonathan M Davis wrote: [SNIP] the default assignment operator illegal. You could overload it, and as long as it doesn't touch any of the const member variables, it would work, but the const member

Re: const attribute makes whole element const?

2012-09-11 Thread monarch_dodra
On Tuesday, 11 September 2012 at 09:00:15 UTC, Ali Çehreli wrote: On 09/10/2012 02:49 AM, monarch_dodra wrote: On Sunday, 9 September 2012 at 23:54:45 UTC, Jonathan M Davis wrote: [SNIP] the default assignment operator illegal. You could overload it, and as long as it doesn't touch any

Re: const attribute makes whole element const?

2012-09-10 Thread Jacob Carlborg
On 2012-09-10 02:05, Namespace wrote: I had never problems with that in C++. If I have members which are const because they are assigned only one time and needs no other assignment, why should I declare this member not as const? In the example I know exactly that I assign only one time a name

Re: const attribute makes whole element const?

2012-09-10 Thread Jonathan M Davis
On Monday, September 10, 2012 09:13:04 Jacob Carlborg wrote: On 2012-09-10 02:05, Namespace wrote: I had never problems with that in C++. If I have members which are const because they are assigned only one time and needs no other assignment, why should I declare this member not as const?

Re: const attribute makes whole element const?

2012-09-10 Thread Jacob Carlborg
On 2012-09-10 09:24, Jonathan M Davis wrote: And it works just fine in D2. It's const that's the problem. In general, if you want a member variable to be read-only on a struct, I'd strongly advise using a getter property without a setter property rather than making it const, because const makes

Re: const attribute makes whole element const?

2012-09-10 Thread Jonathan M Davis
On Monday, September 10, 2012 09:30:59 Jacob Carlborg wrote: On 2012-09-10 09:24, Jonathan M Davis wrote: And it works just fine in D2. It's const that's the problem. In general, if you want a member variable to be read-only on a struct, I'd strongly advise using a getter property without a

Re: const attribute makes whole element const?

2012-09-10 Thread monarch_dodra
On Sunday, 9 September 2012 at 23:54:45 UTC, Jonathan M Davis wrote: [SNIP] the default assignment operator illegal. You could overload it, and as long as it doesn't touch any of the const member variables, it would work, but the const member variable is stuck as it is, and anything trying

Re: const attribute makes whole element const?

2012-09-10 Thread Jonathan M Davis
On Monday, September 10, 2012 11:49:48 monarch_dodra wrote: It appears that when writting: tests[4] = Test(Foobar); It *looks* like compiler is eliding the opAssign/CC completely, opting for a bit copy, which is illegal. As I believe was mentioned elsewhere in this thread, that's due to

Re: const attribute makes whole element const?

2012-09-10 Thread monarch_dodra
On Monday, 10 September 2012 at 09:54:46 UTC, Jonathan M Davis wrote: On Monday, September 10, 2012 11:49:48 monarch_dodra wrote: It appears that when writting: tests[4] = Test(Foobar); It *looks* like compiler is eliding the opAssign/CC completely, opting for a bit copy, which is illegal. As

Re: const attribute makes whole element const?

2012-09-09 Thread monarch_dodra
On Saturday, 8 September 2012 at 23:18:14 UTC, Timon Gehr wrote: On 09/09/2012 01:16 AM, Namespace wrote: Why fail this code? without const on Name it works fine. http://dpaste.dzfl.pl/9fa0986a const fields cannot be written to. This includes the case when the entire struct is written to

Re: const attribute makes whole element const?

2012-09-09 Thread Namespace
On Saturday, 8 September 2012 at 23:18:14 UTC, Timon Gehr wrote: On 09/09/2012 01:16 AM, Namespace wrote: Why fail this code? without const on Name it works fine. http://dpaste.dzfl.pl/9fa0986a const fields cannot be written to. This includes the case when the entire struct is written to

Re: const attribute makes whole element const?

2012-09-09 Thread Ali Çehreli
On 09/09/2012 08:09 AM, Namespace wrote: On Saturday, 8 September 2012 at 23:18:14 UTC, Timon Gehr wrote: On 09/09/2012 01:16 AM, Namespace wrote: Why fail this code? without const on Name it works fine. http://dpaste.dzfl.pl/9fa0986a const fields cannot be written to. This includes the

Re: const attribute makes whole element const?

2012-09-09 Thread Jonathan M Davis
On Sunday, September 09, 2012 17:09:23 Namespace wrote: On Saturday, 8 September 2012 at 23:18:14 UTC, Timon Gehr wrote: On 09/09/2012 01:16 AM, Namespace wrote: Why fail this code? without const on Name it works fine. http://dpaste.dzfl.pl/9fa0986a const fields cannot be written

Re: const attribute makes whole element const?

2012-09-09 Thread Namespace
I had never problems with that in C++. If I have members which are const because they are assigned only one time and needs no other assignment, why should I declare this member not as const? In the example I know exactly that I assign only one time a name to this struct, so why I should not

Re: const attribute makes whole element const?

2012-09-09 Thread Jonathan M Davis
On Monday, September 10, 2012 02:05:08 Namespace wrote: I had never problems with that in C++. If I have members which are const because they are assigned only one time and needs no other assignment, why should I declare this member not as const? In the example I know exactly that I assign

Re: const attribute makes whole element const?

2012-09-09 Thread Timon Gehr
On 09/10/2012 02:05 AM, Namespace wrote: I had never problems with that in C++. clang++ sez: error: cannot define the implicit default assignment operator for 'S', because non-static const member 'x' can't use default assignment operator If I have members which are const because they are

const attribute makes whole element const?

2012-09-08 Thread Namespace
Why fail this code? without const on Name it works fine. http://dpaste.dzfl.pl/9fa0986a

Re: const attribute makes whole element const?

2012-09-08 Thread Timon Gehr
On 09/09/2012 01:16 AM, Namespace wrote: Why fail this code? without const on Name it works fine. http://dpaste.dzfl.pl/9fa0986a const fields cannot be written to. This includes the case when the entire struct is written to at once.