[Development] qsizetype and classes working with QStrings or QList
Matthew Woehlke
mwoehlke.floss at gmail.com
Fri Aug 28 19:45:16 CEST 2020
On 25/08/2020 15.15, André Pönitz wrote:
> On Mon, Aug 24, 2020 at 09:46:43AM +0200, Mathias Hasselmann wrote:
>> C++ also has a solution for that problem: [1]
>> https://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/
>
> AAA is a non-solution from the ivory tower.
>
> It's a pain for human reviewers and tools operating on less then a full
> translation unit.
>
> (Almost) real-world example:
>
> for (auto i = foo.guess_stuff(); --i >= 0; )
> do_something(i);
>
> Good? Bad?
Bad, *but*...
for (auto const i : indexRange(foo.guess_stuff()) | range::reverse)
do_something(i)
...better! ;-) Also answers Scott's question.
(I'll assume `do_something` is actually something complicated enough
that std::for_each or the like wouldn't be preferred. Also note that
exact spelling of the above will depend on where you are getting range
utilities; in my case, I'm lucky if I can use C++14, so I have my own
implementations.)
BTW, AAA encourages duck typing, which may be a good or bad thing
depending on your perspective.
--
Matthew
More information about the Development
mailing list