On Sunday, 26 January 2014 at 14:29:54 UTC, matovitch wrote:

s/immutable/enum/

?

I am a *total* beginner so I am sure my code should look at least strange to experts. How should I write this ? Why ?

I am not sure exactly what are you trying to achieve. My comment meant "ditch immutable, replace with enum" :) Also ditch array() calls. This compiles:

import std.array;
import std.range;
import std.traits;
import std.algorithm;

template isBernstein(alias K) {
enum bool isBernstein = (K.empty || isNumeric!(typeof(K.front)));
}

struct Bernstein(alias K, int S) if (isBernstein!K)
{
    enum kernel = K;
    enum shift = S;
}

template reverse(alias B)
{
alias reverse = Bernstein!(retro(B.kernel), -(B.shift + cast(int)B.kernel.length - 1));
}

template alternate(alias B)
{
alias alternate = Bernstein!(map!(a => a[0] * a[1])(zip(B.kernel, cycle([-1, 1]))), B.shift);
}

void main() {
    alias haar_scale = alternate!(Bernstein!([1.,1.], 0));

    writeln(haar_scale.kernel);
    writeln(haar_scale.shift);
}

I don't know if it works as intended though.

ps : It seems the compiler lost the type information when unpacking the tuple ?

Which tuple?

This code doesn't compile :

template alternate(alias B)
{
    alias alternate = Bernstein!(
        array(map!(a => a[0])(zip(B.kernel, cycle([-1, 1])))),
        B.shift);
}

It does for me.

Reply via email to