Real-world code base example

This example is from a real-world code base, although variable names has been disguised. As it is only a cut-out, you don't have to understand the logic of the code. The example is here just to show you how the complexity is lowered when using algorithms compared with nested for-loops.

Using algorithms will also make the code cleaner. You can often write functions without nesting. In the for-loop version, it's hard to grasp when conflicting textures are set to true, whereas in the algorithm version, you can instinctively see that it happens if info fulfills a predicate.

Note that kvp is short for key-value-pair.
The for-loop version The STL algorithm version
auto varies() -> bool {...}auto conflicting = ...

Get C++ High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.