Should this work?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jan 10 21:44:11 PST 2014


On Fri, Jan 10, 2014 at 04:03:53AM +0100, Timon Gehr wrote:
> On 01/10/2014 02:19 AM, Brad Anderson wrote:
> >On Friday, 10 January 2014 at 00:52:27 UTC, H. S. Teoh wrote:
> >>
> >><snip>
> >>
> >>So to summarize:
> >>(1) use sig constraints to define the scope of an overload; and
> >>(2) use static if inside the function body (or template body) to
> >>enforce type requirements within that scope.
> >>
> >>This solves the problem of needing the compiler to somehow read your
> >>mind and figure out exactly which of the 56 overloads of find() you
> >>intended to match but failed to.
> >>
> >>
> >>T
> >
> >Ok, you've convinced me. I still think highlighting which constraints
> >failed should happen but for well implemented modules like those in
> >the standard library your approach offers even more helpful and tight
> >error messages.
> 
> static assert is not a good way to implement custom error messages
> because it also changes the behaviour of the declaration.

It's not just about custom error messages; it's about picking up a
particular template signature even when you don't have an implementation
for it, because logically speaking, your set of overloads *should* pick
up all such instantiations to begin with. This is why I differentiated
between the scope of a template, vs. the actual available overloads.

With sig constraints, you're declining instantiations that don't satisfy
certain conditions; I'm arguing that sometimes you *want* to accept
instantiations that you currently don't implement (yet), because it
falls under the logical scope of what you intend to handle; you just
haven't gotten around to actually implementing it yet.


T

-- 
Stop staring at me like that! It's offens... no, you'll hurt your eyes!


More information about the Digitalmars-d mailing list