digitalmars.D.learn - struct opCall - use cases
- Brother Bill (3/3) Aug 08 What are some use cases where struct opCall would be useful?
- H. S. Teoh (7/10) Aug 08 When the struct is intended to be a function object. I.e., a type that
- monkyyy (7/10) Aug 08 Glue code, someone was fairly good about trying to hide all
- Bradley Chatha (4/7) Aug 08 I've used it my Lua wrapper to give it a slightly more natural
What are some use cases where struct opCall would be useful? As far as I know, this capability is unique to D. Do any other languages support this?
Aug 08
On Fri, Aug 08, 2025 at 02:11:48PM +0000, Brother Bill via Digitalmars-d-learn wrote:What are some use cases where struct opCall would be useful?When the struct is intended to be a function object. I.e., a type that abstracts a function.As far as I know, this capability is unique to D. Do any other languages support this?C++. Not that that's a good example of what a language should do. :-D T -- What did the epileptic have for lunch? Seizure salad.
Aug 08
On Friday, 8 August 2025 at 14:11:48 UTC, Brother Bill wrote:What are some use cases where struct opCall would be useful? As far as I know, this capability is unique to D. Do any other languages support this?Glue code, someone was fairly good about trying to hide all implementation details, contrary to popular belief, syntax sugar has syntactic meaning. 95% of the base cases of the fundamental syntax are "scary hidden control flow" escape hatches. In the most exterme cases you can nest structs with opDispatch, opCall is fairly mild mannered bit of meta programming hacking.
Aug 08
On Friday, 8 August 2025 at 14:11:48 UTC, Brother Bill wrote:What are some use cases where struct opCall would be useful? As far as I know, this capability is unique to D. Do any other languages support this?I've used it my Lua wrapper to give it a slightly more natural interface when calling Lua functions from D: https://github.com/BradleyChatha/lumars/blob/master/source/lumars/function_.d#L138
Aug 08