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

Add support for use move-only type as parameter in signal which only has one slot #43

Closed
xyz1001 opened this issue Feb 25, 2024 · 1 comment

Comments

@xyz1001
Copy link

xyz1001 commented Feb 25, 2024

Could you please add support for this code?

#include <iostream>

#include <sigslot/signal.hpp>

class Foo {
public:
    Foo() = default;
    ~Foo() = default;

    Foo(const Foo &) = delete;
    Foo &operator=(const Foo &) = delete;

    Foo(Foo &&) = default;
    Foo &operator=(Foo &&) = default;

public:
    void Test() {
        SigTest(std::make_unique<int>(3));
    }

public:
    sigslot::signal<std::unique_ptr<int> &&> SigTest;
};

class Bar {
public:
    Bar() = default;
    ~Bar() = default;

    Bar(const Bar &) = delete;
    Bar &operator=(const Bar &) = delete;

    Bar(Bar &&) = default;
    Bar &operator=(Bar &&) = default;

public:
    void OnTest(std::unique_ptr<int> arg) {
        std::cout << "arg: " << *arg << std::endl;
    }
};

int main() {
    Foo foo;
    Bar bar1;
    Bar bar2;
    foo.SigTest.connect(&Bar::OnTest, &bar1);
    // foo.SigTest.connect(&Bar::OnTest, &bar2); // should be compile time error or runtime error
    foo.Test();
    return 0;
}

Currently I need use std::shared_ptr as parameter, which will cause it is hard to manage lifetime.

Maybe a new signal type which only take one slot is possible way to implement it.

@palacaze
Copy link
Owner

Duplicate of #18

@palacaze palacaze marked this as a duplicate of #18 Mar 17, 2024
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

2 participants