Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a new delegate specialization #19

Open
uselessgoddess opened this issue Jul 16, 2021 · 2 comments
Open

Create a new delegate specialization #19

uselessgoddess opened this issue Jul 16, 2021 · 2 comments

Comments

@uselessgoddess
Copy link
Member

We can create ConstDelegate or UniqueDelegate, or NonMutableDelegate and others
For support the follow style:

auto GlobalDelegate = Delegate(...);

// change follow function
{
    GlobalDelegate Delegate(shared ptr to object, ptr to method);
}

// case #1 - create from standart delegate
{
    auto delegate = NEW_DELEGATE_NAME(GlobalDelegate);
    WorkFunc(delegate);
}

// case #2 - create from ref to object and ptr to method
auto global_ptr = std::shared_ptr(...);
{
    auto delegate = NEW_DELEGATE_NAME(*global_ptr, &decltype(*global_ptr)::FOO);
    WorkFunc(delegate);
}

// case #3 - create from ref to object and ptr to method
auto global_ptr = std::shared_ptr(...);
{
    Object object = ...;
    auto delegate = NEW_DELEGATE_NAME(object, &Object::FOO);
    WorkFunc(delegate);
}

// case #4 - create from unique_ptr to object and ptr to method
auto global_ptr = std::shared_ptr(...);
{
    auto object = std::unique_ptr(...);
    auto delegate = NEW_DELEGATE_NAME(object, &decltype(*object)::FOO);
    WorkFunc(delegate);
}

The main purpose of such a delegate is to avoid creating a std::shared_ptr.
Since it can use only objects from its own visibility zone or from a higher one, there will be no problems with dangling pointers

P.S. also can use Platform::Delegates::Delegate template specialization

@uselessgoddess
Copy link
Member Author

Sorry, @Konard . Reference in C++ do not store its lifetime

@uselessgoddess
Copy link
Member Author

For example:

MulticastDelegate<const char *()> delegate;
{
    auto ptr = std::make_shared<std::string>("hello");

    // PLEASE SELECT YOUR CAULDRON IN HELL

    // zombie patter
    delegate = [=]() { return ptr->c_str(); };

    // use after free
    delegate = [&]() { return ptr->c_str(); };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant