18.09.2012 1:56, bearophile пишет:
Denis Shelomovskij:
Just want to mention about existent (and more flexible than this
syntax) library solution.
Search for `Bind` here:
https://bitbucket.org/denis_sh/misc/src/tip/stdd/typetuple.d
Its ddocs show this:
import std.traits;
static assert(is(staticBind!(CommonType, long, allArgs).Res!int == long));
static assert(!staticBind!(isImplicitlyConvertible, arg!0, int).Res!long);
static assert( staticBind!(isImplicitlyConvertible, int ,
arg!0).Res!long);
alias staticBind!(staticMap, Unqual, allArgs).Res UnqualAll;
static assert(is(UnqualAll!(const(int), immutable(bool[])) T) &&
T.length == 2 && is(T[0] == int) && is(T[1] ==
immutable(bool)[]));
I have understood the meaning and usage of those "type lambdas" that use
? in Scala as soon I have seen them, while I don't get much from this
noisy stuff :-(
Bye,
bearophile
Yes, my library solution is rather ugly (but still doesn't know why it
isn't as obvious as Scala's one). Just added a clearer one (if somebody
needs this). Search for "Binds template arguments using format string."
(second `Bind` template) here (if you want):
https://bitbucket.org/denis_sh/misc/src/tip/stdd/typetuple.d
To conclude:
Your proposal:
alias Tuple!(int, ?, ?) T;
My first solution:
alias staticBind!(Tuple, int, arg!0, arg!1).Res T;
My second solution:
mixin Bind!q{ Tuple!(int, %0, %1) T };
From docs:
Binds template arguments using format string.
Example:
----
import std.traits;
mixin Bind!q{ CommonType!(long, %*) CommonTypeToLong };
static assert(is(CommonTypeToLong!int == long));
mixin Bind!q{ isImplicitlyConvertible!(%0, int)
isImplicitlyConvertibleToInt };
static assert(!isImplicitlyConvertibleToInt!long);
mixin Bind!q{ isImplicitlyConvertible!(int, %0)
isImplicitlyConvertibleFromInt };
static assert( isImplicitlyConvertibleFromInt!long);
mixin Bind!q{ staticMap!(Unqual, %*) UnqualAll };
static assert(is(UnqualAll!(const(int), immutable(bool[])) T) &&
T.length == 2 && is(T[0] == int) && is(T[1] ==
immutable(bool)[]));
--
Денис В. Шеломовский
Denis V. Shelomovskij