Immutability and other attributes, please review

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


On 14.06.2012 20:32, Roman D. Boiko wrote:
> On Thursday, 14 June 2012 at 16:24:43 UTC, Jonathan M Davis wrote:
>> On Thursday, June 14, 2012 17:32:03 Roman D. Boiko wrote:
>>> I don't know how to put a variable of type float to the heap
>>
>> auto f = new float;
>> *f = 2.1;
>>
>> - Jonathan M Davis
>
> Except for immutable I would need to cast when passing into a function.
> That's dangerous, given that *f might be changed later. But looks like
> Timon's suggestion from my other question should work.
>
> immutable a = [2.1].ptr;
>

That or pack the logic into a pure function, e.g. this should work:

immutable ap = newPureFloat(3.1415);

float* newPureFloat(float val)pure
{
	float* p = new float;
	*p = val;
	return p;
}

-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list