Gentoo Archives: gentoo-dev

From: "Jan Kundrát" <jkt@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] How to support C++11 in libraries?
Date: Fri, 20 Dec 2013 12:36:10
In Reply to: [gentoo-dev] Re: How to support C++11 in libraries? by Martin Vaeth
1 On Friday, 20 December 2013 10:00:43 CEST, Martin Vaeth wrote:
2 > The example with string reference-counters which you gave is IMHO
3 typical;
4 > one would really need to write strange code to make it work *with*
5 reference
6 > counters but break without. Hard to believe that this happens in
7 practice.
8 > What *will* happen in practice is that the execution speed changes
9 (probably
10 > getting slower, but there might also be exceptions).
12 You have not considered the implications of the updated requirements. With
13 std::string, this might be hard to understand within all the layers of
14 template wrapping, but consider std::list instead.
16 The "old" (C++98/C++03) std::list is implemented by containing exactly one
17 member, the struct _List_node_base. This struct has exactly two pointers
18 inside, one for the next item and one for the last. This layout cannot be
19 changed without breaking the binary compatibility; it is effectively made
20 public because GCC's standard library does not use the PIMPL idiom.
22 Now, this particular layout (which we just established cannot be changed
23 without breaking the ABI) means that std::list::size() has O(n) time cost
24 simply because it has to traverse the whole list to compute the number of
25 items. The C++11 standard, however, mandates the time complexity to be
26 O(1). This means that there will be a very visible change, at least for
27 std::list. I won't speculate on how the upstream is going to solve this,
28 but I do not expect that the end result will allow linking a translation
29 unit built for C++98 by GCC <= 4.8 with one built for C++11 by the new
30 compiler.
32 Jan


Subject Author
[gentoo-dev] Re: How to support C++11 in libraries? Martin Vaeth <vaeth@××××××××××××××××××××××××.de>