[Development] unified data model API in QtCore => thin wrapper proposal

Thiago Macieira thiago.macieira at intel.com
Fri Oct 5 17:35:10 CEST 2018


On Friday, 5 October 2018 04:25:05 PDT Edward Welbourne wrote:
> dev (5.13):
> QCborValue{Ref,}::operator[] added where missing
> https://codereview.qt-project.org/240042
>
> The first's const-ing and the second's padding are needed in 5.12 to let
> the last be backwards-compatible, when it lands.  Once the first two land,
> we can finally close the qtbase API review.

May as well bring this question to the list as a whole now:

QCborValue, Array and Map have methods like:

	const QCborValue operator[](qint64 index) const;

We're trying to figure out if the returned type should be const.

Pros:
 1) once QCborValue can be modified by the APi above, you can't accidentally 
use it in a const object
 2) you can't write
   array[n] = newValue;

Cons:
 Suppresses move construction as in
    QCborValue v = array[n];
this still compiles, but passes through the copy constructor, not the move 
one. We cana add an extra move constructor for const QCborValue && if 
necessary.

Eddy: what happens in the new API if you write:
  const QCborArray array = { QCborArray{ 1 } };
  QCborValue v = array[0];
  v[0] = 2;

Does that modify array?


-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center






More information about the Development mailing list