anyway to set a const object after the fact?

aliak something at something.com
Tue Oct 30 11:28:27 UTC 2018


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 
part of D though I guess. So meh.

>
> 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

Ya, I was looking to bind once. Like what you can do this with a 
module constructor:

const int a;
static this() {
   a = 5;
}




More information about the Digitalmars-d-learn mailing list