← Back to team overview

dolfin team mailing list archive

Re: Checking if shared_ptr is NULL

 

On Tue, Feb 01, 2011 at 10:55:28PM +0000, Garth N. Wells wrote:
>
>
> On 01/02/11 21:46, Anders Logg wrote:
> > On Tue, Feb 01, 2011 at 01:36:59PM -0800, Johan Hake wrote:
> >> On Tuesday February 1 2011 13:18:54 Anders Logg wrote:
> >>> What is the correct way to check whether a shared_ptr is NULL?
> >>
> >> What with:
> >>
> >>  bool has_child() const
> >>  {
> >>    return _child.count()!=0;
> >>  }
> >
> > Will try that.
> >
> >> or just or implement a constructor for Hierarchical which initialize the
> >> shared_ptr to 0?
> >
> > I was under the impression it's always initialized to 0,
>
> That's true.

Yes (tested now).

It's also the case that checking whether a shared_ptr is NULL can be
done in many ways:

if (ptr == 0)

if (!ptr)

if (ptr.use_count() == 0)

if (ptr == shared_ptr<Foo>()) // I think

--
Anders


> Garth
>
> and
> > initialization to zero should be handled by
> >
> > _foo = shared_ptr<foo>();
> >
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp



References