Parameter with indetermined tuple elements type?

oddp oddp at posteo.de
Mon Jan 11 17:01:22 UTC 2021


On 11.01.21 16:27, Marcone via Digitalmars-d-learn wrote:
> function [...] without template.

And why don't you want to use templates for that? It's as easy as that:

import std;

auto foo(T)(T tup) if (isTuple!T) {
     // statically introspect tuple here ...
     return tup;
}

void main()
{
     writeln(foo(tuple(1, "2", '3')));
     writeln(foo(tuple()));
     //writeln(foo("not a tuple")); // fails to compile
}

[1] https://run.dlang.io/is/VYk9Y9


More information about the Digitalmars-d-learn mailing list