
Beautiful code series


Beautiful code #5 - std::for_each, std::ranges::for_each, std::optional, std::execution::par_unseq, mutable ๐
std::for_each
, std::ranges::for_each
, std::optional
, and std::execution::par_unseq
are features from C++20 and C++23 that helps efficiently loop through the loop, loop in parallel, add optional values in the data structure of your choice, etc.

Beautiful code #4 - std::any_of, std::none_of, std::all_of - efficient C++20 feature๐
std::any_of
, std::none_of
and std::all_of
is a C++20 feature that helps efficiently check for basic conditions in the data structures. This is very optimal because of early termination once some fact is found and the algorithm don’t have to iterate more to further prove anything before returning the result.

Beautiful code #3 - [[no_unique_address]] - sophisticated and simple C++20 feature๐
[[no_unique_address]]
is a C++ 20 feature that helps in saving memory while declaring an empty struct or class and creating object for it in some other place.

Beautiful code #2 - enable_if_t and template inside a template code ๐
In this short article, I have posted a code snippet that uses enable_if_t
to handle SFINAE and also showed how to use a template inside a template.

Beautiful code #1 - Using define, templates and r-value reference ๐
In this short article, I have posted an example that does the reinterpret_cast
on an integer and convert it to char pointer and then the value pointed by the char pointer is converted to r-value reference all in a macro.