Problems with nesting boost::container::small_vector and C++98
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
Hi,
typedef std::pair
> mypair;
If I'm replacing 'mypair' with 'mystruct':
struct mystruct {
mystruct& operator=(const mystruct& other) {
i = other.i;
sv = other.sv;
return *this;
}
int i;
small_vector
Attached the source file with 'mypair' replaced by 'mystruct'.
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
using boost::container::small_vector;
typedef std::pair
> mypair; typedef std::map
mymap; typedef std::map > mymap2; typedef std::map , 8> > mymap3; int main() { mymap m; mypair& sv = m[0];
mymap2 m2; small_vector
& sv2 = m2[0]; mymap3 m3; small_vector
, 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-declare... 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.htm... and http://www.boost.org/doc/libs/1_63_0/doc/html/container/known_issues.html#co... Best, Ion
On Sun, Jan 01, 2017 at 10:30:14PM +0100, Ion Gaztañaga wrote:
So the problem you are facing it's a limitation of the move emulation library.
Thank you for the info! It seems a bit unfortunate that the move emulation library breaks that easily. Greetings, Daniel
participants (2)
-
Daniel Trstenjak
-
Ion Gaztañaga