Add support for use move-only type as parameter in signal which only has one slot
xyz1001 opened this issue · comments
xyz1001 commented
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.
Pierre-Antoine Lacaze commented
Duplicate of #18