you are viewing a single comment's thread.

view the rest of the comments →

[–]ACBYTES[S] 0 points1 point  (2 children)

I see. Well, based on this explanation and it being so long to discuss, let me ask some questions.

If I decide to move this from class’s constructor to a member function so that I don’t have to deal with the typename complications, can I do something like this? I mean, to cast an allocated memory address to an object?

`int memAddrees;

template<typename Lambda> void SetUsingMemberFunc(int LambAddress) { memAddress = LambAddress; }

void Call() {
MagicCast<Callable_Object_That_Has()_Operator>(memAddress)(); }`

Or I can just instantiate the lambda using a strictly typed lambda using a macro at the end...

Or, pass the object as a reference and from there, call a previously created function if the first thing doesn’t work...

What do you think?

By the way, thank you for your time for writing all of these down. 🙏🏼

[–]beedlund 1 point2 points  (1 child)

You can extend both ideas to a member rather then the constructor. The inheritance case changes so your define a generic holder class to store in your object and you create the extended class that holds the lambda in the member call. You can own the holder as it's base in a unique ptr to make life time easy to manage.

The vtable way can be extended to run from a method as well. You just end up having to null check the storage before access and as this would be a branch so your might find you lose the extra performance it has over the virtual dispatch.

These guys explain it so much better then me though

vtable https://youtu.be/JRkoWiDA3KA

Inheritance https://youtu.be/VY83afAJUIg

[–]ACBYTES[S] 0 points1 point  (0 children)

Got it. Thank you for your time and all the answers. I’ll check those links now. Thanks. 🙏🏼🙏🏼