On Mon, Oct 29, 2018 at 09:50:32PM +0000, 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 + 1 .. $]; > break; > } > others ~= arg; > } > // "others" is a list of args before the valid arg is encountered > // "restArgs" is a list that is the args after the valid arg > } > } > > Is there anyway to set a const object after declaring it in the above > context? [...]
What exactly are you trying to accomplish? I.e., what semantics do you want from modifying restArgs? If you're looking to rebind the array, just be a bit more explicit in how you spell out the type: const(string)[] restArgs; will allow you to rebind it to a different array / slice, but still not permit you to modify the array elements. T -- Дерево держится корнями, а человек - друзьями.