
Den 05-05-2011 13:59, Stewart, Robert skrev:
Thorsten Ottosen wrote:
Some dislike "naked" pointers in interfaces. I think a good guide line is that such pointer is always without ownership, and so
T* foo()
is quite easy to read IMO. No need for another overload.
That is a viewpoint you cannot impose on library users, however.
Well, how does the library user knows that an optional<T&> does not own the stored reference? Can I say delete &*find_some_thing() ? To be sure, I must consult the documentation. Just by looking at the name of the function find_some_thing() it would be highly surprising if that involved transfer of ownership of a resource. Don't get me wrong: I'm a great fan of optional<T>, but that does not imply that you can't use it too much. -Thorsten