A possible suggestion for the Foreach loop
Tommi
tommitissari at hotmail.com
Wed Aug 21 03:02:31 PDT 2013
On Wednesday, 21 August 2013 at 02:46:06 UTC, Dylan Knutson wrote:
> [..]
> ----------------------------------------------------------------------
> T foo(T)(ref T thing)
> {
> thing++; return thing * 2;
> }
>
> foreach(Type; TupleType!(int, long, uint))
> {
> unittest
> {
> Type tmp = 5;
> assert(foo(tmp) == 12);
> }
>
> unittest
> {
> Type tmp = 0;
> foo(tmp);
> assert(tmp == 1);
> }
> }
> ----------------------------------------------------------------------
> [..]
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);
}
}
}
More information about the Digitalmars-d
mailing list