Re: anyway to set a const object after the fact?

2018-10-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 30, 2018 2:18:15 AM MDT Laurent Tréguier via Digitalmars-d-learn wrote: > On Monday, 29 October 2018 at 21:50:32 UTC, aliak wrote: > > Hi, so if you have this piece of code: > > > > struct C { > > > > void f() { > > > > string[] others; > > const string[] restArgs; >

Re: anyway to set a const object after the fact?

2018-10-30 Thread Laurent Tréguier via Digitalmars-d-learn
On Tuesday, 30 October 2018 at 11:23:48 UTC, aliak wrote: Guess I could do that. But would there be a difference if I just declared the restArgs as non const then? Given the objective is "set this var to point to this thing and not allow it to be set to point to anything else". The

Re: anyway to set a const object after the fact?

2018-10-30 Thread aliak via Digitalmars-d-learn
On Monday, 29 October 2018 at 22:05:16 UTC, H. S. Teoh wrote: What exactly are you trying to accomplish? I.e., what semantics do you want from modifying restArgs? Trying to set restArgs to point to some data but only set it once. Would require some sort of control flow analysis on the

Re: anyway to set a const object after the fact?

2018-10-30 Thread aliak via Digitalmars-d-learn
On Tuesday, 30 October 2018 at 08:18:15 UTC, Laurent Tréguier wrote: On Monday, 29 October 2018 at 21:50:32 UTC, aliak wrote: Hi, so if you have this piece of code: struct C { void f() { string[] others; const string[] restArgs; foreach (i, arg; args) { if

Re: anyway to set a const object after the fact?

2018-10-30 Thread aliak via Digitalmars-d-learn
On Monday, 29 October 2018 at 22:12:24 UTC, Paul Backus wrote: Use a lambda: const string[] restArgs = () { foreach(i, arg; args) { if (isValidArg(arg)) { return args[i+1 .. $]; } others ~= arg; } }(); That works.

Re: anyway to set a const object after the fact?

2018-10-30 Thread Laurent Tréguier via Digitalmars-d-learn
On Monday, 29 October 2018 at 21:50:32 UTC, aliak wrote: Hi, so if you have this piece of code: struct C { void f() { string[] others; const string[] restArgs; foreach (i, arg; args) { if (isValidArg(arg)) { restArgs = args[i + 1 .. $]; break; }

Re: anyway to set a const object after the fact?

2018-10-29 Thread Paul Backus via Digitalmars-d-learn
On Monday, 29 October 2018 at 21:50:32 UTC, aliak wrote: Hi, so if you have this piece of code: struct C { void f() { string[] others; const string[] restArgs; foreach (i, arg; args) { if (isValidArg(arg)) { restArgs = args[i + 1 .. $]; break; }

Re: anyway to set a const object after the fact?

2018-10-29 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Oct 29, 2018 at 09:50:32PM +, aliak via Digitalmars-d-learn wrote: > Hi, so if you have this piece of code: > > struct C { > > void f() { > string[] others; > const string[] restArgs; > foreach (i, arg; args) { > if (isValidArg(arg)) { > restArgs = args[i