typedefs are useless

BCS BCS at pathlink.com
Mon Dec 3 12:38:58 PST 2007


Steven Schveighoffer wrote:
> This may have arisen somewhere before, but...
> 
> Let's say I want a way to create a type that's like a long, but is not 
> implicitly convertable from a long.
[...]

this is getting really close to something I have wanted for some time:

typedef real MyReal
{
    // stuff
}

it would be like a struct that inherits from a primitive type. The this 
would be of the base type and you wouldn't be allowed to add any 
members. However this would allow you to do things like overload the 
operators. The one things in particular I would like to do would be to 
overload just the typing of the operators. This would result in the 
implementation of + (for instance) being the same as + on the underlying 
type, but the type of the result would be redefined. The point of this 
would be to allow a program to restrict the type that could be used. A 
concrete use case would be a SIUinits type that would, at compile time, 
verify unit correctness, but in the end would result in exactly the same 
code as if bare FP values were used.

Thoughts?



More information about the Digitalmars-d mailing list