On Wednesday, 21 August 2013 at 10:02:33 UTC, Tommi wrote:

Why not just do this:

import std.typetuple;

T foo(T)(ref T thing)
{
    thing++; return thing * 2;
}

unittest
{
    foreach(Type; TypeTuple!(int, long, uint))
    {
        {
            Type tmp = 5;
            assert(foo(tmp) == 12);
        }

        {
            Type tmp = 0;
            foo(tmp);
            assert(tmp == 1);
        }
    }
}

Well, that's one way to go about doing it. But, this seems sub-optimal because a defining trait of unittests is that they're as small and focused on a single behavior for an object/function/whatever as possible. Grouping all testing into a single unittest breaks this convention.

Not to mention, we've got 'static if', and 'static assert', which can exist outside of function bodies and operate on compile time determinable values. It seems like a strange exception for foreach (which can already operate on compile time values) to be excluded from this group.

Reply via email to