Out of bound problem

bearophile bearophileHUGS at lycos.com
Sun Feb 17 01:37:24 PST 2008


Thanks to everybody, in my code I did solve the problem like this:
result = foo(a, b.dup[0]);

But I was curious to know what you think about this situation. Now I know it's probably a compiler bug.


Christopher Wright:
> Y'know, there's a template for this in std.traits and tango.core.Traits.

I don't use Tango (yet). I use always the std lib when possible, I know there's no point in duplicating the std lib. I don't remember the bugs or the problems, but I have found std.traits not enough for similar array purposes, and I have found a bug in the traits of Tango to do that array purposes, so I have created IsArray and IsDynamicArray, you can find them in my d libs:

template IsArray(T) {
    const bool IsArray = is(typeof(T.length)) && is(typeof(T.sort)) &&
                         is(typeof(T.reverse)) && is(typeof(T.dup));
}
template IsDynamicArray(T) {
    const bool IsDynamicArray = is( typeof(T.init[0])[] == T );
}
template IsStaticArray(T) {
    const bool IsStaticArray = IsArray!(T) && (!IsDynamicArray!(T));
}

That IsArray may look a bit like "duck typing at compile time", but that's the only thing that works that I have found.
I use similar tools all the time, so I need to have them quite sharp :-)

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list