Producing nicer template errors in D libraries
Jacob Carlborg
doob at me.com
Wed Apr 11 01:07:54 PDT 2012
On 2012-04-10 21:45, H. S. Teoh wrote:
> A lot of template code (e.g. a big part of Phobos) use signature
> constraints, for example:
>
> void put(T,R)(R range, T data) if (isOutputRange!R) { ... }
>
> This is all nice and good, except that when the user accidentally calls
> .put on a non-range, you get reams and reams of compiler errors
> complaining that certain templates don't match, certain other
> instantiations failed, etc., etc.. Which is very unfriendly for newbies
> who don't speak dmd's dialect of encrypted Klingon. (And even for
> seasoned Star Trek^W^W I mean, D fans, it can take quite a few seconds
> before the real cause of the problem is located.)
Original I would have gone with something like:
struct OutputRange
{
void foo ();
void bar ();
}
void put(T,OutputRange R)(R range, T data)
Or:
void put(T,R : OutputRange)(R range, T data)
Something like that.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list