Bug 4916 – struct VariantN does not overload ()

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-09-22T20:11:00Z
Last change time
2013-10-24T18:31:27Z
Keywords
pull
Assigned to
andrei
Creator
ah08010-d
Depends on
4053

Comments

Comment #0 by ah08010-d — 2010-09-22T20:11:45Z
This code: ============== module scratch; import std.variant; unittest { Variant v; int foo() { return 1; } v = &foo; v(); } ================ Produces this error: ================ $ dmd -unittest -run bronze/util/scratch.d bronze\util\scratch.d(12): Error: struct VariantN does not overload () =============== IMO, this is a design flaw: Variants claim to support function and delegate pointers, and it seems obvious that supporting them should support invoking them. (In particular, since functions and delegates are different sizes, Variants should be very useful in this role, except ...)
Comment #1 by sandford — 2011-01-09T08:43:29Z
Note that as listed in Bug 4053, struct constructors and opCall are not compatible, so the v() syntax isn't possible. In the update to variant I've been working on, I've added a .call method, which supports functions, delegates, opCall, etc. Also, multi-argument opCall should be supported: unittest { Variant v; int foo(int x, int y) { return x+y; } v = &foo; assert(v(4,6) == 10); } See https://jshare.johnshopkins.edu/rjacque2/public_html/variant.mht
Comment #2 by andrei — 2013-02-26T09:07:24Z
Comment #3 by github-bugzilla — 2013-10-24T18:30:41Z