Re: Auto keyword with const variable

2013-07-25 Thread Dicebot
On Wednesday, 24 July 2013 at 11:26:32 UTC, Mike Parker wrote: This is the exact behavior I would expect. I think of auto as this variable is going to be the same type as that variable. Since in is const int, then j also is going to be const int. If you want to copy n into a nonconst variable,

Auto keyword with const variable

2013-07-24 Thread Alex H
This code: void test(const int n) { auto j = n; j++; } Gives this error: cannot modify const expression j Is this considered a feature or a bug? I would assume most people wouldn't want new variables inheriting const.

Re: Auto keyword with const variable

2013-07-24 Thread bearophile
Alex H: void test(const int n) { auto j = n; j++; } Gives this error: cannot modify const expression j Is this considered a feature or a bug? I would assume most people wouldn't want new variables inheriting const. It's a bit annoying. I don't remember people discussing

Re: Auto keyword with const variable

2013-07-24 Thread MGW
On Wednesday, 24 July 2013 at 08:07:55 UTC, Alex H wrote: This code: void test(const int n) { auto j = n; j++; } Gives this error: cannot modify const expression j Is this considered a feature or a bug? I would assume most people wouldn't want new variables inheriting

Re: Auto keyword with const variable

2013-07-24 Thread dennis luehring
Am 24.07.2013 11:39, schrieb bearophile: Alex H: void test(const int n) { auto j = n; j++; } Gives this error: cannot modify const expression j Is this considered a feature or a bug? I would assume most people wouldn't want new variables inheriting const. It's a bit

Re: Auto keyword with const variable

2013-07-24 Thread bearophile
dennis luehring: and how would it look to preserve the const if auto would auto-rip it of? You could write: immutable j = n; For every default behavour you need a way to implement the other nicely :-) Currently for the problem of the OP you can use this: Unqual!(typeof(n)) j = n; Bye,

Re: Auto keyword with const variable

2013-07-24 Thread monarch_dodra
On Wednesday, 24 July 2013 at 10:01:14 UTC, bearophile wrote: dennis luehring: and how would it look to preserve the const if auto would auto-rip it of? You could write: immutable j = n; For every default behavour you need a way to implement the other nicely :-) Currently for the

Re: Auto keyword with const variable

2013-07-24 Thread Artur Skawina
On 07/24/13 12:09, monarch_dodra wrote: Keeping it to same type, 100% of the time seems like the best. No, it's a design bug. The head qualifier(s) should always be stripped when copying objects. Stripping is always fine (ie safe), not doing it just creates other problems, like the one in OP, or

Re: Auto keyword with const variable

2013-07-24 Thread monarch_dodra
On Wednesday, 24 July 2013 at 10:37:40 UTC, Artur Skawina wrote: On 07/24/13 12:09, monarch_dodra wrote: Keeping it to same type, 100% of the time seems like the best. No, it's a design bug. The head qualifier(s) should always be stripped when copying objects. Stripping is always fine (ie

Re: Auto keyword with const variable

2013-07-24 Thread Mike Parker
On Wednesday, 24 July 2013 at 08:07:55 UTC, Alex H wrote: This code: void test(const int n) { auto j = n; j++; } Gives this error: cannot modify const expression j Is this considered a feature or a bug? I would assume most people wouldn't want new variables inheriting

Re: Auto keyword with const variable

2013-07-24 Thread Jonathan M Davis
On Wednesday, July 24, 2013 10:07:54 Alex H wrote: This code: void test(const int n) { auto j = n; j++; } Gives this error: cannot modify const expression j Is this considered a feature or a bug? I would assume most people wouldn't want new variables inheriting const. The

Re: Auto keyword with const variable

2013-07-24 Thread bsd
On Wednesday, 24 July 2013 at 11:26:32 UTC, Mike Parker wrote: ... This is the exact behavior I would expect. I think of auto as this variable is going to be the same type as that variable. Since in is const int, then j also is going to be const int. If you want to copy n into a nonconst