|
Boost Users : |
From: dick.bridges_at_[hidden]
Date: 2003-04-24 10:27:10
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"
<eddielee_at_tropic To: boost-users_at_[hidden]
soft.com> cc:
Sent by: news Subject: [Boost-Users] Re: "Correct" way to return empty shared_ptr?
<news_at_main.gmane
.org>
04/23/2003 05:47
PM
Please respond
to Boost-Users
dick.bridges_at_[hidden] wrote:
> 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_at_[hidden]>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net