Boost logo

Boost Users :

Subject: Re: [Boost-users] class API return a const&, optional, shared_ptr
From: Alan M. Carroll (amc_at_[hidden])
Date: 2008-11-25 08:08:00


I prefer the static class member option. Note that it is *not* necessary for clients to have access to that static if the type has a well defined invalid value. This is true for shared_ptr. If the static member is null, then clients need merely check the returned pointer in the normal fashion, as they should any returned pointer.

On the other hand, one might ask why you would want to return a const ref to a shared_ptr. That one can cheaply return copies is one of the big features of shared_ptr.

At 07:15 AM 11/25/2008, Hicham Mouline wrote:
>hello,
>
>I have a class A that holds a container of objects of type B indexed by int
>for e.g.
>
>Typically, I have a function of A
>
>class A {
>public:
> const B& getB(int <index> ) const;
>private:
> std::map< int, shared_ptr<B> > listOfBs_;
>};


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