"else if" for template constraints
Enamex via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 4 09:25:05 PDT 2015
On Friday, 4 September 2015 at 15:52:08 UTC, Enamex wrote:
> The biggest problem, I think, is that a template can has
> multiple 'predicates' to agree to be instantiated, but only
> some of them can mutually exclusive (the specialization syntax
> produces mutually exclusive ones, the if-constraints don't).
> [...]
> template Bar(T) {
> static if( is(T == int) || is(T == string) || ... ) {
> //stuff
> }
> else static if( stuff ) {
> // other stuff
> }
> else {
> template return; // I know my T took whatever your type
> was but I actually don't match, please exclude me from your
> list for this instance...
> }
> }
> [...]
On second thought, it wouldn't help as much as I'd thought with
overloading problems. What we want is a 'which template has more
'&&'ed expressions in its constraint?' which sounds pretty awful.
I have no idea how this could work :/
Especially given that D's constraints are way more open than,
say, Haskell's, in their checking; though ironically not their
declaration/implementation (D is open because it checks for
structural conformance of a struct instead of nominative &
structural; but it's more restricted because it easily only
checks for structure of the type as declared, with no way to
attach recognized-to-the-constraint ad-hoc interfaces to a type
like Haskell's with type-classes).
More information about the Digitalmars-d
mailing list