On Thursday, 1 October 2015 at 02:06:48 UTC, Fusxfaranto wrote:
/** Returns: true iff all values $(D V) are the same. */
template allSame(V...)          // TODO restrict to values only
{
    static if (V.length <= 1)
        enum bool allSame = true;
    else
        enum bool allSame = V[0] == V[1] && allSame!(V[1..$]);
}

std.traits to the rescue!

http://dlang.org/phobos/std_traits.html#isExpressions

Using isExpressions!V as a template constraint looks like the behavior you're looking for.

Thanks!

BTW: Is there some way to turn the recursive definition of `allSame` into an iterative definition?

Reply via email to