Article by Ayman Alheraki on January 11 2026 10:35 AM
Given that C++17 is fully implemented in all compilers, while C++20 and C++23 are still not fully supported in most compilers, I will highlight here the most impactful additions in C++17.
C++17 didn't just bring a set of improvements and modifications, but it introduced a comprehensive quantum leap in the world of programming. Let's delve into the most prominent features this version brought, with practical examples illustrating its power and flexibility.
1. Enhancing performance and efficiency:
std::string_view: Allows efficient handling of text, especially in operations that don't require modifying the original text.
std::string_view sv = "Hello, world!";std::cout << sv.substr(0, 5); // Output: Hello
std::optional: Provides a safe way to handle values that may or may not exist, reducing potential errors.
std::optional<int> result = divide(10, 2);if (result) { std::cout << *result; // Output: 5}2. Simplifying code writing:
Type deduction in if and switch: Variables can now be defined directly within these structures, making the code more clear.
if (std::optional<int> result = divide(10, 2); result) { std::cout << *result;}if constexpr: Allows executing specific code only if a certain condition is met at compile time, improving performance and reducing errors.
template <typename T>auto get_value(T value) { if constexpr (std::is_pointer_v<T>) { return *value; } else { return value; }}3. Strengthening functional programming:
std::invoke: Facilitates the uniform invocation of functions and function objects.
std::vector<int> v = {1, 2, 3};std::invoke(std::sort, v.begin(), v.end());
std::apply: Allows applying a function to a set of arguments stored in a std::tuple.
auto sum = std::apply([](auto... args) { return (args + ...); }, std::make_tuple(1, 2, 3));4. Improvements in the standard library:
std::filesystem: Provides a unified API for interacting with the file system.
std::variant: Allows storing values of different types in the same variable.
std::any: Allows storing values of any type in the same variable.
5. Enhancing parallelism:
Execution policies: Facilitates controlling how parallel algorithms are executed.
Parallel algorithms: Provides parallel versions of many standard algorithms.
Conclusion:
C++17 represents a quantum leap in the programming world. It not only improved performance and efficiency but also introduced new and innovative tools that make writing code easier and more powerful and flexible. If you are a C++ developer, exploring these additions and applying them to your projects will open up new horizons of creativity and innovation.