Daily bit(e) of C++ | std::ranges projections
Daily bit(e) of C++ ♻️141, Simpler and more readable code through std::ranges projections.
One of the major additions in the C++20 ranges library is support for projections.
Projections are transformations applied before the element is passed to the corresponding invocable (e.g. to a strict-weak-ordering predicate for sort).
Algorithms that operate on multiple source ranges provide a separate projection for each range.
As a reminder, taking the address of standard functions (including member functions) is undefined behaviour, e.g. can't project to string length by using &std::string::length directly.
Great bite! What to do if you want to project std::string::length?
Have you ever thought of sharing these as Anki cards? Might be more beneficial to the community! Thanks.