tuple of delegates requires explicit type
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Wed Jun 20 12:08:28 UTC 2018
On Wednesday, June 20, 2018 11:43:52 DigitalDesigns via Digitalmars-d wrote:
> alias f = void delegate();
> Tuple!(f)[] fs;
>
> fs ~= tuple(() { });
>
> fails but
>
> fs ~= Tuple!(f)(() { });
>
> passes.
> in tuple, it is seeing the lambda as void and thinks I'm trying
> to append a tuple of void. I don't see why the compiler can't see
> that it works.
The types don't match.
---
import std.typecons;
alias f = void delegate();
void main()
{
pragma(msg, typeof(tuple((){})));
pragma(msg, typeof(Tuple!f((){})));
}
---
prints
Tuple!(void function() pure nothrow @nogc @safe)
Tuple!(void delegate())
tuple is instantiated and evaluated independently of what's done with the
result, so the fact that you're then appending it to a Tuple!f[] is
irrelevant. By the point it tries to append, it's already determined the
type of what it's trying to append, and because you didn't specify the type,
it's what it gets inferred as, which is not the same type as you have in the
array.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list