lundi 27 juin 2016

What is the proper way to change the key of an element in an std::map >?

What is the proper way to change the key of an element in an std::map< std::unique_ptr<T> >?

This is what I tried:

std::unique_ptr< T > temp = std::move( mp.find( oldKey )->second );
mp.erase( oldKey );
mp.insert( std::make_pair( newKey, std::move( temp ) ) );

But it doesn't work due to unique_ptr(const unique_ptr&) = delete;

Aucun commentaire:

Enregistrer un commentaire