r/cpp • • Dec 15 '21

Modern C++ in Advent of Code

This series, by Šimon Tóth, is a step by step guide through the solutions of Advent of Code 2021 using Modern C++.

242 Upvotes

83 comments sorted by

View all comments

Show parent comments

7

u/[deleted] Dec 15 '21

Honestly, it's not. I really pushed it and this solution is actually undefined behaviour since the lambdas are not regular invocable.

But I do think that from a software engineering perspective, moving to ugly functional code will be a good move. Simply because it makes static analysis so much more powerful.

I wish we could write beautiful functional code in C++, but I don't think that will ever happen :-D

25

u/[deleted] Dec 16 '21

It's an unreadable mess. I do not for the life of me understand why people have an issue with seeing a for or while loop. They think it is bad code for some reason which is just bizarre to me. It's far easier to read and shows you *what is actually happening*. It is much better than code compressed into chained, filthy functional bollocks.

4

u/[deleted] Dec 16 '21

Do you really consider this:

auto [min, max] = data | filter(&MyClass::isReady) | minmax_element();

less readable than the equivalent loop & if.

4

u/Enemiend Dec 16 '21

IMO it may be more readable for a C++ dev that regularly works with this kind of syntax. For everybody else, no, a loop & if is more readable, if you ask me. Opinions may differ.