Multiple Tuple IFTI Syntactic Sugar
Christopher Wright
dhasenan at gmail.com
Sun Feb 1 16:41:50 PST 2009
dsimcha wrote:
> I've been thinking about how IFTI works for variadic function templates. I
> use variadic functions heavily in the infotheory module of dstats, and am
> looking to add some features here. Currently, my mutual information function
> looks like:
>
> real mutualInfo(T, U)(T[] x, U[] y);
>
> I'd like to generalize this so that both x and y can be any number of vectors,
> yielding in standard mathematical notation, something like I(x, y; z, a),
> which is the mutual information of (x, y) as a joint distribution with (z, a)
> as a joint distribution. However, trying to turn this into D code with decent
> notation leads to some headaches:
>
> real mutualInfo(T..., U...)(T x, U y);
How do you instantiate that?
mutualInfo!(TypeTuple!(T1, T2, T3), TypeTuple!(T4, T5, T6))?
No, the tuples would be flattened.
Bearophile's suggestion can be implemented something like:
struct MutualInfo(T...)
{
T x;
auto opCall(U...)(U y) {}
}
MutualInfo!(T...) mutualInfo(T...)(T args)
{
// etc
}
More information about the Digitalmars-d
mailing list