Boost logo

Boost Users :

Subject: Re: [Boost-users] Problems with nesting boost::container::small_vector and C++98
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2017-01-01 16:30:14


On 31/12/2016 17:44, Daniel Trstenjak wrote:
> Hi,
>
>
> first the used versions:
> boost 1.63.0
> gcc 5.4.0 20160609
> Ubuntu 16.04.1
>
>
> the example I've problems with is:
>
> #include <map>
> #include <boost/container/small_vector.hpp>
>
> using boost::container::small_vector;
>
> typedef std::pair<int, small_vector<float, 8> > mypair;
>
> typedef std::map<int, mypair> mymap;
> typedef std::map<int, small_vector<mypair, 8> > mymap2;
> typedef std::map<int, small_vector<small_vector<float, 8>, 8> > mymap3;
>
> int main()
> {
> mymap m;
> mypair& sv = m[0];
>
> mymap2 m2;
> small_vector<mypair, 8>& sv2 = m2[0];
>
> mymap3 m3;
> small_vector<small_vector<float, 8>, 8>& sv3 = m3[0];
> }

In C++98 std::pair copy constructor is implicitly declared. Since
small_vector declares operator= taking a non-const reference (as that's
how move semantics are emulated), then std::pair's operator= takes a
non-const pair argument:

http://en.cppreference.com/w/cpp/language/copy_assignment#Implicitly-declared_copy_assignment_operator

So the problem you are facing it's a limitation of the move emulation
library. When you define your own class holding a small_vector, you have
the same problem. When you explicitly declare operator= taking a const
reference the problem is solved.

See:

http://www.boost.org/doc/libs/1_63_0/doc/html/move/emulation_limitations.html

and

http://www.boost.org/doc/libs/1_63_0/doc/html/container/known_issues.html#container.known_issues.move_emulation_limitations

Best,

Ion


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