If my class SomeType has a method that returns a element from the map (using the key) say
std::unique_ptr<OtherType> get_othertype(std::string name)
{
return otMap.find(name);
}
that would enure the caller would recieve a pointer to the one in the map rather than a copy? Is it ok to do this, or would it try and call the copy constructor (and fail as it has been removed) because it is being returned?
Assuming I must use unique_ptr as my map items.
UPDATE::
After trying to implement the code, it seems that unique_ptr and std:map/:pair dont work together in gcc 4.4.4, pair just didnt like unique_ptr as a type parameter. (see http://stackoverflow.com/questions/2286828/cant-create-map-of-moveconstructibles).
I changed the ptr to std::shared_ptr and it all worked.
I suppose I can use the same code with the shared pointer?