User Tools

Site Tools


cpp17

CPP17 - C++ 17

Return to C++: CPP Standards, C++11, C++14, C++20 and C++23

C++17, formally known as ISO/IEC 14882:2017, introduced a suite of features aimed at simplifying code, improving performance, and enhancing the type safety of C++ programs. This summary, presented in MediaWiki format, outlines the significant updates and improvements incorporated into C++17.

Structured Bindings

C++17 introduced structured bindings, allowing developers to unpack elements from tuples, pairs, and struct-like objects into separate named variables, simplifying code that works with tuple-based return types.

`if` and `switch` with Initializers

This feature allows an initializer to be included in `if` and `switch` statements, promoting more concise code by limiting the scope of variables used in conditions.

Inline Variables

C++17's inline variables facilitate the definition of variables in header files without leading to multiple definition errors, a boon for header-only libraries and shared constants.

`constexpr` Lambda Expressions

Expanding the contexts in which `constexpr` can be used, C++17 enables lambda expressions to be evaluated at compile time, enhancing the language's metaprogramming capabilities.

`std::optional`, `std::variant`, and `std::any`

These types introduce more expressive ways to handle optional, type-safe union, and type-erased values, respectively, making error handling and variant type management more straightforward.

Filesystem Library

The inclusion of the `<filesystem>` library provides a standard way to perform file and directory operations, addressing a long-standing gap in the standard library.

Parallel Algorithms

C++17 added support for parallel execution of standard algorithms, allowing for easy utilization of multi-core processors for improved performance.

`std::string_view`

`std::string_view` offers a lightweight, non-owning view into a string, enabling more efficient string handling without unnecessary copies.

`std::apply` and `std::invoke`

These functions facilitate calling a function or callable object with arguments supplied in a tuple or derived from different types, streamlining the invocation of callable objects.

Fold Expressions

Fold expressions simplify the writing of variadic template functions by enabling easy accumulation or combination of all arguments passed to a template.

`std::byte`

The introduction of `std::byte` provides a type-safe way of representing byte data, distinct from character types, emphasizing its use for raw memory access.

`[[nodiscard]]` and `[[maybe_unused]]` Attributes

These attributes allow developers to indicate that a function's return value should not be ignored and to suppress warnings for intentionally unused entities, improving code safety and cleanliness.

`std::clamp`

`std::clamp` offers a straightforward way to constrain a value within a specified range, enhancing the readability and simplicity of common boundary-checking operations.

Template Argument Deduction for Class Templates

This feature simplifies the use of templates by allowing the compiler to deduce the template arguments for constructors of class templates, reducing boilerplate code.

`std::shared_mutex`

`std::shared_mutex` and `std::shared_lock` introduce shared ownership locks, enabling more fine-grained control over read-write access in multithreaded applications.

`std::scoped_lock`

Replacing `std::lock_guard` with `std::scoped_lock` provides a more flexible way to handle multiple mutexes simultaneously, mitigating the risk of deadlock.

`std::variant` `std::visit`

Alongside `std::variant`, C++17 introduced `std::visit`, a mechanism to apply a visitor to a variant's currently held type, simplifying type-safe operations on variant types.

Guaranteed Copy Elision

C++17 specifies conditions under which the compiler must elide copies and moves of class objects, reducing unnecessary copying and moving, and potentially improving performance.

Removal of Trigraphs

The removal of trigraphs from C++17 eliminates a source of confusion and potential errors in code, streamlining the language's syntax.

Deprecated and Removed Features

C++17 deprecated and removed several features, such as `auto_ptr`, `register` keyword, and boolean ++ operator, to clean up the language and discourage unsafe or unclear practices.

Conclusion

C++17 represents a significant evolution of the C++ language, introducing features that enhance its usability, performance, and safety. By addressing both long-standing issues and adopting new programming paradigms, C++17 ensures the language's continued relevance and utility for modern software development.

For detailed information on C++17 features and technical specifications, the official ISO C++ website and the GitHub repository for the C++ Standards Committee's documents are invaluable resources. Unfortunately, direct links to these resources cannot be provided here, but they are readily accessible through official channels and repositories dedicated to the C++ standard.

This summary outlines the breadth of improvements and new features introduced in C++17, showcasing the standard's commitment to evolving in response to the needs of the programming community while maintaining backward compatibility and performance.

C++: C++ Fundamentals, C++ Inventor - C++ Language Designer: Bjarne Stroustrup in 1985; C++ Keywords, C++ Built-In Data Types, C++ Data Structures (CPP Containers) - C++ Algorithms, C++ Syntax, C++ OOP - C++ Design Patterns, Clean C++ - C++ Style Guide, C++ Best Practices ( C++ Core Guidelines (CG)) - C++ BDD, C++ Standards ( C++ 23, C++ 20, C++ 17, C++ 14, C++ 11, C++ 03, C++ 98), Bjarne Stroustrup's C++ Glossary, CppReference.com, CPlusPlus.com, ISOcpp.org, C++ Compilers (Compiler Explorer, MinGW), C++ IDEs, C++ Development Tools, C++ Linter, C++ Debugging, C++ Modules ( C++20), C++ Packages, C++ Package Manager ( Conan - the C/C++ Package Manager), C++ Standard Library, C++ Libraries, C++ Frameworks, C++ DevOps - C++ SRE, C++ CI/CD ( C++ Build Pipeline), C++ Data Science - C++ DataOps, C++ Machine Learning, C++ Deep Learning, Functional C++, C++ Concurrency, C++ History, C++ Topics, C++ Bibliography, Manning C++ Series, C++ Courses, CppCon, C++ Research, C++ GitHub, Written in C++, C++ Popularity, C++ Awesome , C++ Versions. (navbar_cplusplus – see also navbar_cpp_containers, navbar_cppcon, navbar_cpp_core_guidelines, navbar_cpp23, navbar_cpp20, navbar_cpp17, navbar_cpp14, navbar_cpp11)


© 1994 - 2024 Cloud Monk Losang Jinpa or Fair Use. Disclaimers

SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.


cpp17.txt · Last modified: 2024/04/28 03:12 by 127.0.0.1