user defined literals

Trass3r un at known.com
Fri Mar 25 09:54:46 PDT 2011


Steven Schveighoffer Wrote:
> Aside from the parsing issues, which I think would be minor, it's more of  
> a problem with anyone and his mother is allowed to define literal types.

Yeah that's true.

> That is, someone could have 1fud and I'm not sure what the hell that  
> means, so I have to go find out where that xyz is defined.  It must be  
> global, since literals can be used anywhere, so it can be anywhere.

Well the user defined literals could only be used in places where the module containing the proper opSuffix implementation is imported. The search for that doesn't really differ from the search for any other poorly named function or type or whatever.
I do agree though that suffixes would mostly be very short and could get very cryptic.


> > auto dist = 1km;
> > sin(90deg);
> 
> These are good points, but of course, units are open to interpretation.   
> Not every unit has a standard abbreviation, and not every abbreviation is  
> unique.
> 
> These things are highly context sensitive.  For example, I could say:
> 
> auto mytime = 1h + 3m + 4s;
> auto mydistance = 15m;

Probably one of the biggest problems of the whole concept.

> Not only that, but it's compile-time, meaning there is no actual call to  
> some operator processor to generate the timestamp.

You forget CTFE ;)


More information about the Digitalmars-d mailing list