What are the new features in C++17?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
C++17, officially known as ISO/IEC 14882:2017, is an update to the C++ language standard, following C++14. It includes several new language features, library updates, and improvements aimed at increasing the performance, reliability, and clarity of C++ code. Let's discuss some significant features and details of C++17.
Language Features
1. Structured Bindings
Structured bindings allow unpacking tuple, pair, or struct into individual named variables.
2. if and switch with Initializers
This feature allows an initializer statement before the condition in if and switch statements, improving scope control and readability.
3. Inline Variables
Inline variables provide a way to define variables in header files without multiple definition errors, simplifying the management of global constants.
Library Features
1. Filesystem Library
The filesystem library (<filesystem>) provides facilities for performing operations on file systems and their components.
2. Parallel Algorithms
The Standard Library now includes support for parallel execution of algorithms.
New Template Features
1. std::variant, std::optional, and std::any
These types provide more flexible data structures that can be used to represent a value that may either hold a value of one type (std::optional), any type (std::any), or one of a set of types (std::variant).
Language Clarifications and Fixes
constexprLambda Expressions: Lambdas can now beconstexpr, enhancing the capabilities of compile-time computations.- Fold Expressions: Simplifies the generation of variadic template code using fold expressions for arbitrary operations.
Summary Table
| Feature | Description | Example Usage |
| Structured Bindings | Unpack data structures into individual named elements | auto [x, y, z] = get_tuple(); |
if and switch Initializers | Add initializers in conditionals | if (auto it = m.find(key); it != m.end()) |
| Inline Variables | Allow inline global variables | inline const int max_value = 100; |
| Filesystem Library | Perform operations on file systems | fs::create_directory("example"); |
| Parallel Algorithms | Execute algorithms in parallel | std::for_each(std::execution::par,...); |
std::variant | Hold one of a set of types | std::variant<int, float> v = 1; |
std::optional | Represent an optional value | std::optional<std::string> opt = "example"; |
std::any | Hold a value of an arbitrary type | std::any a = 1.5; |
constexpr Lambda Expressions | Use lambdas in constant expressions | auto f = []() constexpr { return 1; }; |
| Fold Expressions | Simplify generation of variadic templates | template<typename... Args>(Args... args) { return (args + ...); } |
Additional Considerations
In addition to these features, C++17 also makes several smaller feature adjustments and bug fixes to improve the overall language consistency. These updates reflect the ongoing evolution of C++ to meet the needs of modern software development while maintaining backward compatibility with older code bases.
For developers, migrating to C++17 offers opportunities for cleaner, more efficient, and maintainable code with robust library support and enhanced language facilities.

