References to const

Steven Schveighoffer schveiguy at yahoo.com
Thu Nov 13 07:14:31 PST 2008


"Andrei Alexandrescu" wrote
> Steven Schveighoffer wrote:
>> Would it make sense to have shortcuts to Rebindable that automatically 
>> apply const or invariant?  something like:
>>
>> template tconst(T)
>> {
>>    alias Rebindable!(const(T)) tconst;
>> }
>>
>> Using whatever you think is best for a symbol name.  Just something a 
>> little shorter.
>
> Better yet (or in addition to), we could make it a function so argument 
> deduction takes care of everything.
>
> Rebindable!(const T) tailconst(const T r);
> Rebindable!(immutable T) tailimmutable(const T r);
>
> auto w = new Widget;
> auto w1 = tailconst(w);
> w1 = tailconst(new Widget);

These could be useful.  Also, another reason for having a rebindable type is 
that you don't have to initialize it upon declaration, so having a shorter 
type for declaration would still be beneficial.

-Steve 





More information about the Digitalmars-d mailing list