Template constraints

Nick Treleaven via Digitalmars-d digitalmars-d at puremagic.com
Thu Feb 19 06:27:10 PST 2015


On 16/02/2015 19:31, Steven Schveighoffer wrote:
> Wait, isn't this OK?
>
> struct S(T) if(is(T == int))
> {
>    ...
> }
>
> struct S(T) if(is(T == double))
> {
>    ...
> }
...
> They may even be in multiple modules.
>
> Is this not "overloading" of types? I don't think this should be frowned
> upon.

OK, so the idea might not be appropriate for types. What about for 
methods though - if a method doesn't have overloads, static assert might 
be better than a constraint. Even where there are overloads, (part of) 
the constraint may be OK to push into static assert instead for better 
error messages.

> I think instead of this, we should try and just make the messages
> better. Note that something like you are suggesting requires much
> rewriting of code.

True, but until the compiler improves perhaps we could use this 
technique for methods e.g. in new code.


More information about the Digitalmars-d mailing list