Boost logo

Boost Users :

Subject: Re: [Boost-users] Flyweight: wrapping shared_ptr
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2014-10-09 06:35:28


Akim Demaille <akim <at> lrde.epita.fr> writes:

>
> I think it now does what I want, if you're curious:
>
> http://coliru.stacked-crooked.com/a/cacc6107cf22c2e6

Looks neat!
 
> I made several changes:
>
> [...]
>
> - but so I also need to support null pointers, so I have added
> support for nullptr and operator bool.

I think you forgot to add that support in some of poly_older ctors
and assignment operators:

  poly_holder(const poly_holder& x);
  poly_holder& operator=(const poly_holder& x);
  poly_holder& operator=(poly_holder&& x);

> - FWIW, your operator== for poly_flyweight was uselessly deep,
> comparing the addresses should suffice

You're right, your version is the right one.

> (actually, shouldn't
> Boost.Flyweight provide these operators itself? Is there any
> possibility that something else would be wanted? I'm also
> thinking about hashing here).

Currently, the following overloads are provided:

  ==,<,!=,>,>=,<=,swap,<<

hash was not provided for no particular reason, but I'll consider
adding it (both for boost::hash and std::hash). As for what these
overloads are not serving your poly_flyweight, the problem is that in

  poly_flyweight<Base> f1,f2;

  f1==f2; // ambiguity

the == expression is probing many implicit conversions (to
poly_flyweight<Base>, to poly_holder<Base>, to Base) resulting in
ambiguities: this is why you need to suply your own == etc. for
poly_flyweight.

Good luck with you project.

Joaquín M López Muñoz
Telefónica


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