Now, imagine the following situation: we have a resource that cannot be copied, which should be correctly freed in a destructor, and we want to return it from a function:
descriptor_owner construct_descriptor()
{
return descriptor_owner("Construct using this string");
}
Actually, you can work around such situations using the swap method:
void construct_descriptor1(descriptor_owner& ret)
{
descriptor_owner("Construct using this string").swap(ret);
}
However, such a workaround does not allow us to use descriptor_owner in containers. By the way, it looks awful!