c++ - boost::signals::scoped_connection doesn't work in std::vector. why? -


as understand it, scoped_connections meant automatically disconnect when go out of scope, , not before. i've found doesn't work correctly when scoped_connection in std::vector (and fails other containers well).

eg.

using boost::signals::scoped_connection; // readability boost::signal<void ()> sig; std::vector<scoped_connection> connection_vec;  connection_vec.push_back(sig.connect(foo)); assert(connection_vec.back().connected()); // assertion fails! 

i've seen explained claiming std::vector requires elements copyable whereas scoped_connection uncopyable - that's not entirely true. std::vector requires elements moveable. (and expect scoped_connection should moveable.)

for example, following code works:

std::vector<std::unique_ptr<scoped_connection>> vec2; // note std::unique_ptr uncopyable, moveable  vec2.push_back(std::unique_ptr<scoped_connection>(new scoped_connection(sig.connect(foo)))); assert((*vec2.back()).connected()); // assertion succeeds! 

besides, if problem due std::vector trying copy uncopyable thing, shouldn't produce compiling error?

so i'm wondering actual reason scoped_connection not working correctly inside vector, , problem can fixed within boost.

(i tested on gcc version 4.8.0 boost version 1.53.0.)

scoped_connection has no move constructor (yet). not movable assume, instead std::move fallback copy. , mentioned cannot copy around scoped_connection.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -