Implementing Half Floats in D

TommiT tommitissari at hotmail.com
Tue Jan 29 04:16:53 PST 2013


On Tuesday, 29 January 2013 at 11:26:00 UTC, Timon Gehr wrote:
>
> I'd call it @constfold.

That's a good name. Descriptive and short.

I'm not going to try to push this suggestion any harder, since it 
got no support on the first time I tried it. But I'd like to 
mention just one thing that came to mind:

The generic solution without any extra function attributes:

template ct(alias expr)
{
     enum ct = expr;
}

Literal of type TypeWithNonTrivialConstructor:

ct!(TypeWithNonTrivialConstructor(2.5, 7.5))

The above solution throws the responsibility of the correct use 
of TypeWithNonTrivialConstructor on the end-user. Whereas a 
@constfold attribute on the constructor of 
TypeWithNonTrivialConstructor automates the correct behaviour.


More information about the Digitalmars-d mailing list