Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


On Thu, 2012-02-16 at 10:48 +0400, Ivan Timofeev wrote:
Whoa, I seem to be too naive for patch-reviewing...

Is it a safe code?

     pForbiddenCharacters = &maMap[ nLanguage ];
     return pForbiddenCharacters;

Yeah I don't see anything wrong with it.

Will pForbiddenCharacters point to the deleted object, after the return?

Nope.  As far as I know those STL methods that return its element are
guaranteed to return a reference to the stored instance, not its copy.
So, in theory, taking the address of a returned object which itself is a
reference to the instance stored in the container is very much safe.

The only exception is std::vector<bool> which lumps its internal boolean
values into bitfield, but by doing it it can no longer meet the
requirement of STL container which must return reference to its
elements.  So, by that definition std::vector<bool> is not a STL
container, strictly speaking.

For the curious, refer to Item 18 of Effective STL by Scott Meyers.

Kohei

-- 
Kohei Yoshida, LibreOffice hacker, Calc


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.