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

signal_type add a rvalue operator #4

Closed
qicosmos opened this issue Feb 1, 2016 · 5 comments
Closed

signal_type add a rvalue operator #4

qicosmos opened this issue Feb 1, 2016 · 5 comments
Assignees

Comments

@qicosmos
Copy link

qicosmos commented Feb 1, 2016

hi, the signal_type's opertator is just surpport lvalue, it need a rvalue version, like this.

void operator()(A&&... args) const {
    for (auto const& slot : copy_slots()) {
        if (slot) {
                  slot(std::forward<A>(args)...);
            }
    }
}
@fr00b0 fr00b0 self-assigned this Feb 2, 2016
@fr00b0
Copy link
Owner

fr00b0 commented Feb 7, 2016

Hello,
I'm currently looking into this, but I'm not convinced that it's a good idea to implement. Doing a std::forward in a loop like that will open up some cans of worms.

If I were to add the implementation to the library, the code below will fail catastrophically since the first slot will consume the argument:

auto lambda =
    [&]( std::unique_ptr<int> value ) {
        std::cout << *value << std::endl;
    };

nod::signal<void(std::unique_ptr<int>&&)> signal;
signal.connect( lambda );
signal.connect( lambda );
signal( std::make_unique<int>( 5 ) );

When I get some more time to sit down, I'll look into this some more.

If you don't mind me asking, what are the situation where you need the rvalue version?

@qicosmos
Copy link
Author

hello,
it is meaningless to use rvalue in loop, i just make a unit test, and the code can't be compiled.
this is the code:

    nod::signal<void(string&&)> signal;
    signal.connect([](string&& i){});
    signal(string(""));

so i have to add a rvalue version.

@fr00b0
Copy link
Owner

fr00b0 commented Feb 14, 2016

Yes I understand that your code will not compile. I'm curious about the situation where you need a signal with a rvalue argument. Will you move arguments into your signals? What happens if that signal has multiple slots connected when it is triggered?

@qicosmos
Copy link
Author

I konw your meaning. a rvalue argument in this situation is meaningless. I think you could give some advice to user, maybe somebody makes a mistake.

@fr00b0
Copy link
Owner

fr00b0 commented Dec 6, 2016

I'm closing this issue as it's not implementable, but the issue lives on in issue #12

@fr00b0 fr00b0 closed this as completed Dec 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants