On Friday, 1 March 2013 at 14:39:53 UTC, bearophile wrote:
Andrea Fontana:

double likeness(T,T1)(ref in T1, ref in T2)

==>

double likeness(T1, T2)(in ref T1, in ref T2)

Bye,
bearophile


Sure not the only error. I was writing "pseudo code". Real code it's quite complex.

Try this one (is a really reduced working example):

struct MyStruct(WEIGHTS)
{
        this (int p, int p2) { prop = p; prop2 = p2; }
        int prop;
        int prop2;
        
        alias WEIGHTS weights;
}

double likeness(T1,T2)(ref in T1 first, ref in T2 second)
{
double v = (first.prop - second.prop) * first.weights.foo * second.weights.foo; v += (first.prop2 - second.prop2) * first.weights.bar * second.weights.bar;
        return v;
}

enum FirstWeights : double
{
        foo = 0.3,
        bar = 0.4
}

enum SecondWeights : double
{
        foo = 0.5,
        bar = 0.2
}

void main(string[] args)
{


        auto s1 = MyStruct!FirstWeights(10,8);
        auto s2 = MyStruct!FirstWeights(9, 10);
        auto s3 = MyStruct!SecondWeights(9,10);

        writeln(likeness(s1,s2)); // works
        writeln(likeness(s1,s3)); // works


}

How to put s1,s2,3... in a range/array or something similar/iterable? Probably there's no way (inside variant?)...

Reply via email to