这段代码可以编译,但我认为它没有达到我的预期,即移动,不要复制,boost::any
在堆栈上创建的对象到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)
{
std::cout << boost::any_cast<std::string>(i) << std::endl; // yes a copy exists
}
std::cout << boost::any_cast<std::string>(var) << std::endl; // but this copy still exists too. was it not moved??