Move objects into std::map c++
I have a tree-like structure
class Directory
{
public:
void merge(Directory&& dir);
private:
std::map<Key, Directory> directories;
};
merge shall move each subdirectory in dir into directories. Can this be
done without copying all Keys and directories?
I have tried to say
auto i=dir.begin();
while(i!=dir.end())
{
directories.insert(std::move(*i));
++i;
}
On non-copyable type Key, this fails with deleted copy ctor error for Key.
Would emplace solve the problem? If so, how can I use a workaround for gcc
older than 4.8 which does not support that method?
No comments:
Post a Comment