Andrei's interface requests
Christopher Wright
dhasenan at gmail.com
Sat Apr 4 09:00:34 PDT 2009
Kagamin wrote:
> Andrei Alexandrescu Wrote:
>
>>> 1. If template constraints suck, why not fixing *them*?
>> That's a fix.
>
> This is a fix to interfaces, not to template constraints. If template constraints fail to serve their purpose, what are they for? Make them work, not others to work for them.
This is a change to interfaces to allow them to be used in place of
template constraints in many circumstances. The idea is that the syntax
of template constraints is sufficiently obtuse that you need to use
idioms to get around it:
template AcceptableToTemplate(T)
{
static if (...) // check for non-existence of property 1
{
alias void AcceptableToTemplate;
}
else static if (...) // check for non-existence of property 2
{
alias void AcceptableToTemplate;
}
else
{
alias T AcceptableToTemplate;
}
}
template Template (T : AcceptableToTemplate!(T)) {}
Using that, it's difficult to determine what types you can pass to Template.
More information about the Digitalmars-d
mailing list