<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Hairy Pixels <<a href="mailto:genericptr@gmail.com">genericptr@gmail.com</a>> schrieb am Sa., 4. Nov. 2023, 15:48:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Nov 4, 2023, at 4:22 PM, Sven Barth <<a href="mailto:pascaldragon@googlemail.com" target="_blank" rel="noreferrer">pascaldragon@googlemail.com</a>> wrote:<br>
> <br>
> Then don't assign them every "frame". If you just keep them around then they aren't more expensive than a virtual method call. <br>
> And any other mechanism would involve the heap as well, because that's how anonymous functions that capture variables work and thus anything that wants to store them must play by the same rules. There won't be any changes there. <br>
> <br>
<br>
The need for a universal function pointer type really isn't about the function references even though they work for that, albeit with unneeded overhead.<br>
<br>
Lets say you have a sort function which takes a compare callback parameter. You can make the callback type "is nested" which works on global and nested/anonymous functions but not methods. What if the user wants to provide the compare function as a method because they're calling it in a class which shares the code elsewhere? As the writer of the function you'd need to make 2 versions of the function, one "is nested" and "of object".<br>
<br>
The writer of the sort function shouldn't need to know what kind of function it will be passed, just that a comparison callback is provided, right?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Then you simply make the callback function type a function reference and be done. The user can pass in any kind of function they want and *nearly* every type of function-like pointer.</div><div dir="auto"><br></div><div dir="auto">And if you're really worried about performance when providing such a class then simply provide overloads woth different function-like pointer types, the compiler will pick the most suitable one then. </div><div dir="auto"><br></div><div dir="auto">It's really not that hard as an implementer of a class. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>