[Interest] Qt API annoyances: where to log/discuss?

Jason H jhihn at gmx.com
Wed Oct 31 21:37:17 CET 2018

> Sent: Wednesday, October 31, 2018 at 3:42 PM
> From: "Elvis Stansvik" <elvstone at gmail.com>
> To: "Jason H" <jhihn at gmx.com>
> Cc: "Thiago Macieira" <thiago.macieira at intel.com>, "interest at qt-project.org Interest" <interest at qt-project.org>
> Subject: Re: [Interest] Qt API annoyances: where to log/discuss?
> Den ons 31 okt. 2018 kl 18:35 skrev Jason H <jhihn at gmx.com>:

> > I attempted this recently, but failed to figure out how to do the following:
> > QVector<int> triple = apply(QVector<int> {1,2,3},[](item) { return item*3;});
> > or
> > QVector<int> originals {1,2,3};
> > QVector<int> triples = originals.apply([](item) { return item*3;});
> >
> > My options are std::for_each, std::transform, but they all have an ugly, over-complicated syntax.
> >
> > Compare that to:
> >  std::vector<int> originals { 1,2,3};
> >  std::vector<int> triples;
> >  std::transform(originals.begin(), originals.end(), std::back_inserter(triples), [](int item){ return item*3; });
> Sorry to say it, but welcome to C++ :)
> No, mostly kidding. I think what you suggest sort of makes sense. If
> Qt are to keep its containers, with a goal of offering an alternative
> more convenient/Java-esque API, then a helper member function like you
> suggest seems to fit that goal. Whether Qt still has this as a goal in
> another matter. Maybe not to the extent that they once had?
> For the pattern above, I guess one could make a generic helper in a
> header of the application. I know e.g. Qt Creator has a bunch of such
> helpers in its headers.

I think Qt provides many things, one is an easy-to-read, intuitive API. I don't really think "java-esque" is the right term as Python, JavaScript (my main other languages) read about the same. C++ is out in left field.

When I was reading up on how to do the above, I had to look up back_inserter(), and I don't like it because it violates DRY.
std::transform(A.begin(), A.end(), std::back_inserter(B), ...);
I might complain less if I could do:
std::transform(A, B, ...); but then it's not very clearly assigning, we're actually relying on side-effects so we arrive at:
B = std::transform(A, ...); and now we're not repeating ourselves and not relying on side-effects. This is better than std, and no worse than std, the every way that I care about.

I would be fine with a #include <QtAlgorithms>  that provided this API, rather than put it in the container.

More information about the Interest mailing list