Saturday, 10 August 2013

Is boost::any movable?

Is boost::any movable?

This code compiles but I don't think it does what I intended, that is,
move, don't copy, the boost::any object that was created on the stack into
a std::vector<boost::any>
boost::any var;
var = std::string("StackOverflow");
std::vector<boost::any> vm;
vm.push_back(std::move(var));
for (auto i : vm)
{
cout << boost::any_cast<std::string>(i))) << endl; // yes a copy exists
}
cout << boost::any_cast<std::string>(i))) << endl; // but this copy still
exists too. was it not moved??

No comments:

Post a Comment