Re: [Boost-Users] Re: "Correct" way to return empty shared_ptr?
I don't understand C++ well enough to grok a compiler's interpretation of
the code, but I seems like I'm creating an extra copy for the return. Oh
well, if the snippet seems ok, far be it from me to throw asparagus on it.
;)
Thanks for the help.
"Edward Diener"
What is the 'correct' way to return a NULL/empty shared_ptr? For example, this works
<snippet> shared_ptr<int> maybe_get_a_pointer() { shared_ptr<int> p; return(p); } </snippet>
but seems 'klunky'. I've clearly missed something in the docs/examples somewhere. Can someone point me in the right direction?
What is klunky about it ? It seems pretty normal to me. Another other possibility is to passed a reference to a shared_ptr<> and have your function above fill it in with an actual pointer to int and return a bool true if it succeeded or false if it did not. Another possibility is to use boost::optional<>. Another one to pass back a bool,shared_ptr<> std::pair or boost::tuple. But I prefer the method you used originally. Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
participants (1)
-
dick.bridges@tais.com