typedef boost::multi_index_container<foo, ...
struct foo {
...
std::unique_ptr<Bar> bar; // requires move-semantic only
foo() { bar = std::make_unique<Bar>(); }
foo(foo&&) = default;
};
I haven't any problems with push_back
- just using push_back(std::move(...))
.
Also, no problems with:
auto it = container.get<...>().find(...);
container.erase(it);
But I also need iterate all elements of container. I doing:
for (auto it = container.begin(); auto it = container.end(); ++it) {
some_foo(*it); // For instance, another_container_of_same_type.push_back(*it) - to merge 2 containers
}
Or, in special case:
for (auto it = container.begin(); auto it = container.end(); ++it) {
// some logics
another_container_of_same_type.push_back(*it); //another container defined same as first one
// some logics
}
And it not compiles!
I tried:
some_foo(std::move(*it))
some_foo(std::move(it))
some_foo(it)
some_foo(*it)
Not compiles. It wants copying constructor nor moving...
Warning: NO, it is not simply merging two containers, I using my custom logics in the merging, also using iterating not for merging only.