문제

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)
{
  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?? 
도움이 되었습니까?

해결책

if you look into boost/any.hpp and observe its source code (at least find for move word) you can found that it is totally C++11 unaware (unfortunately)! so you'd better to use boost::any::swap to simulate move assign (if you still want to use boost::any at all)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top