From: tohava on
On Nov 9, 10:27 pm, SG <s.gesem...(a)gmail.com> wrote:
> In C++0x you will be able to write
>
> m.emplace(move(s), move(v));

While I agree that this is the best solution, I think it would also
make sense to have container::insert(const T &&value), which makes use
of the move constructor, making m.insert(make_pair(move(s), move(v))
almost as efficient. (I do not remember if C++0X has this or not).


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Bo Persson on
Jeff Schwab wrote:
> Jeff Flinn wrote:
>> Do any implementations of STL implement copy-on-write
>>> semantics for string or vector?
>>
>> MSVC(VC6)/Dinkumware used to do COW for std::string, but found that
>> small string optimization provided better overall performance.
>
> How does that preclude CoW for non-small strings?

It doesn't, it is a separate optimization, but with an overlap in
effect for short strings.

The original use of CoW for std::string was shown not to work in
practice. Due to the semantics it becomes copy-on-potential-write,
which is most often a net loss - especially for multi-threaded use.

Herb Sutter did the measures that surprised most people:

http://www.gotw.ca/gotw/045.htm


Bo Persson



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Seungbeom Kim on
tohava wrote:
> On Nov 9, 10:27 pm, SG <s.gesem...(a)gmail.com> wrote:
>> In C++0x you will be able to write
>>
>> m.emplace(move(s), move(v));
>
> While I agree that this is the best solution, I think it would also
> make sense to have container::insert(const T &&value), which makes use
> of the move constructor, making m.insert(make_pair(move(s), move(v))
> almost as efficient. (I do not remember if C++0X has this or not).

The latest draft, N2960, has insert member functions that take
rvalue references (P&&, not const P&&, though) for all containers
that have insert member functions.

--
Seungbeom Kim

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]