[Development] QUIP 6: removing top-level const from return types

Marc Mutz marc.mutz at kdab.com
Tue May 23 11:06:14 CEST 2017


On Tuesday 23 May 2017 10:44:11 Ville Voutilainen wrote:
> How is this even a SiC?

Just as you can detect whether a function is overloaded (taking the address 
without cast fails), you can detect the const on the return value. Andre shows 
the difference for QVector. A user could write something like:

   const QVector<T> foo();
   for (auto e : foo()) // foo() returns const, no need to prevent detaching 
       ....

and with dropping the const, it would suddenly detach.

Of course, if you receive a CoWed container, you should not rely on a const 
return type, but enforce const on the call site:

  const auto foos = foo();
  for (auto e: foos)
      ....

This is what makes it a QUIP-6 Cat-A SiC: the latter works with both Qt 
versions, and, arguably, is what should have been written from the get-go.

Thanks,
Marc

-- 
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - The Qt, C++ and OpenGL Experts



More information about the Development mailing list