[Development] Question about QCoreApplicationData::*_libpaths
Thiago Macieira
thiago.macieira at intel.com
Wed Jan 20 22:37:50 CET 2016
On Wednesday 20 January 2016 22:25:27 Kevin Kofler wrote:
> And Qt also has a real
> pop unlike the misleadingly-named STL one: takeLast/takeFirst.
In the Standard Library's defence: the pop() function does not return the
element due to exception-safety. Example:
value_type takeLast() { value_type v = last(); remove(size() - 1); return
v; }
The copy constructor is called once, then the move constructor. If
value_type's move constructor is not noexcept, then it may throw after the
container resized.
You could add this overload to solve it:
void pop(value_type &where) { where = back(); pop(); }
But then your code looks like:
Element e; // may throw, allocate resources, etc.
v.pop(e);
instead of:
Element e = v.back(); // move-constructed
v.pop();
Also note that this overload would keep the integrity of the container, but
not necessarily your data.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Development
mailing list