Immutability and other attributes, please review

Dmitry Olshansky dmitry.olsh at gmail.com
Thu Jun 14 10:58:20 PDT 2012


On 14.06.2012 21:57, Roman D. Boiko wrote:
> On Thursday, 14 June 2012 at 17:44:11 UTC, Jonathan M Davis wrote:
>> I was just thinking that maybe we should make a generic function for
>> this and add it to Phobos. Something like
>>
>> auto makePtr(T, U)(U value) if(is(U : T)) {}
>> auto makePtr(T, Args...)(Args args) {}
>>
>> where the first one works with primitive types and the second one
>> works with
>> structs. Then you could do
>>
>> auto f = makePtr!(immutable float)(2.1);
>>
>> I think that I'll have to see about throwing together something like that
>> tonight and create a pull request.
>>
>> - Jonathan M Davis
> Am I right that [2.0].ptr (instead of 2.0 could be a struct literal)
> doesn't involve copying, while such function would?

Copying what?  One word is surely cheap ;)

-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list