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

Jérôme Godbout godboutj at amotus.ca
Wed Oct 31 22:19:21 CET 2018


All those back_inserter() and C++0xXY template make our life easier in the end, I strongly suggest you do learn them, they can make very generic code with SFINAE that most other language will have hard time to accomplish with the same final level of performance. It's a good balance of quantity of code vs speed. The draw back, is the learning curve and the readability that are hideous.

I agree there is way too much boiler plate for C++ template syntax, but you can design some helper to simplify your SFINAE or other template usage. back_inserter() for example let you make an algo that work with any type of container that will append data, no matter what that container can be, you can even make your own container as long as you provide the push_back() function.

Why use back_inserter over direct push_back? Because some algo like copy operate on iterator and don't need to be rewritten with a push_back version to work, as simple as that. The mor you will stay close to the iterator and the standard, the easier it will be to code with it.

-----Original Message-----
From: Interest <interest-bounces+godboutj=amotus.ca at qt-project.org> On Behalf Of Jason H
Sent: October 31, 2018 4:59 PM
To: giuseppe.dangelo at kdab.com
Cc: interest at qt-project.org
Subject: Re: [Interest] Qt API annoyances: where to log/discuss?



> Sent: Wednesday, October 31, 2018 at 4:30 PM
> From: "Giuseppe D'Angelo via Interest" <interest at qt-project.org>
> To: interest at qt-project.org
> Subject: Re: [Interest] Qt API annoyances: where to log/discuss?
>
> Il 31/10/18 18:35, Jason H ha scritto:
> > 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;});
> 
> You do this:
> 
> > std::vector<int> originals{1, 2, 3}; std::vector<int> triples = 
> > originals | ranges::view::transform([](int i) { return i * 3; });
> 
> (modulo typos). Possibly even without the <int>, as std containers 
> have CTAD.

Thanks Giuseppe! That's getting closer :-) however the expression boggles my mind. "originals | ranges::view::transform" there's a lot of compiler voodoo there. I'm trying to keep up on all the C++0xYZ developments, and still trying to wrap my head around SFINAE. I had to look up CTAD, and that looks like a very good enhancement. I think Qt should hide a lot of that compiler iteration from me ;-) It is an unfortunate phenomenon that I am spending more time decrypting compiler Voodoo. I am thinking that C++ is less a language for writing things in, and rather a language for programming a compiler with the secondary goal of creating an application. <soapbox warning> Too much is being spent on telling the compiler how to build it, rather than just building it. I think this is one thing that Qt can (and should) restore the balance on. "Code less, create more." Spend less time figuring out how to tell the compiler to build it, and let Qt apply() (pun intended) it's transforms to m  ake my effort about application programming not compiler programming.



 


_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list