const as default for variables
Walter Bright via Digitalmars-d
digitalmars-d at puremagic.com
Sat Mar 14 16:54:34 PDT 2015
On 3/14/2015 3:06 PM, Xinok wrote:
> For example, this could be an issue for generic functions:
>
> void foo(T)(T[] arr){
> T value = arr[0]; // Mutable or immutable?
> }
Not really.
const T value = arr[0];
means that value isn't going to be subsequently reassigned or anything mutated
through it.
> Also, you forgot a fifth case where only part of the type is const/immutable:
>
> 5. const(T)[] x = ...
The default const'ness would apply to the [] part.
More information about the Digitalmars-d
mailing list