C++17
As of 2018, C++17 is the name for the most recent revision of the ISO/IEC 14882 standard for the C++ programming language.
History
Before the C++ Standards Committee fixed a 3-year release cycle, C++17's release date was uncertain. In that time period, the C++17 revision was also called C++1z, following C++0x or C++1x for C++11 and C++1y for C++14. The C++17 specification reached the Draft International Standard (DIS) stage in March 2017.[1][2] This DIS was unanimously approved, with only editorial comments,[3] and the final standard was published in December 2017.[4] Few changes were made to the C++ Standard Template Library, although some algorithms in the <algorithm>
header were given support for explicit parallelization and some syntactic enhancements were made.
Next standard
Removed features
This revision of C++ not only added new features but also removed a few.
New features
C++17 introduces many new features. The following lists may not be complete.
Language
- Making the text message for
static_assert
optional[12]
- Allow
typename
(as an alternative toclass
) in a template template parameter[13]
- Nested namespace definitions, e.g.,
namespace X::Y { … }
instead ofnamespace X { namespace Y { … }}
[10][15]
- Allowing attributes for namespaces and enumerators[16][17]
- New standard attributes
[[fallthrough]]
,[[maybe_unused]]
and[[nodiscard]]
[18]
- UTF-8 (
u8
) character literals[16][19] (UTF-8 string literals have existed since C++11; C++17 adds the corresponding character literals for consistency, though as they are restricted to a single byte they can only store ASCII)
- Hexadecimal floating-point literals[20][21]
- A compile-time static
if
with the formif constexpr(expression)
[24]
- Structured binding declarations, allowing
auto [a, b] = getTwoReturnValues();
[25]
- Initializers in
if
andswitch
statements[26]
- copy-initialization and direct-initialization of objects of type
T
from prvalue expressions of typeT
(ignoring top-level cv-qualifiers) shall result in no copy or move constructors from the prvalue expression. See copy elision for more information.
- Some extensions on over-aligned memory allocation[27]
- Template deduction of constructors, allowing
std::pair(5.0, false)
instead ofstd::pair<double, bool>(5.0, false)
- Inline variables, which allows the definition of variables in header files without violating the one definition rule. The rules are effectively the same as inline functions
__has_include
, allowing the availability of a header to be checked by preprocessor directives[28]
- The keyword
register
is now reserved and unused (formerly deprecated)[29]
- Value of
__cplusplus
changed to201703L
[30]
Library
- Most of Library Fundamentals TS I, including:[31][32]
std::string_view
, a read-only non-owning reference to a character sequence or string-slice[33]std::optional
, for representing optional objects, a data type that may not be always be returned by a given algorithm with support for non-returnstd::any
, for holding single values of any type
std::uncaught_exceptions
, as a replacement ofstd::uncaught_exception
in exception handling[34][16]
- New insertion functions
try_emplace
andinsert_or_assign
forstd::map
andstd::unordered_map
key-value associative data structures[35][36]
- A file system library based on
boost::filesystem
[39]
- Additional mathematical special functions, including elliptic integrals and Bessel functions[41]
std::variant
, a tagged union container[42]
std::byte
, allowing char to be replaced for data types intending to model a byte of data as a byte rather than a character[43]
- Logical operator traits:
std::conjunction
,std::disjunction
andstd::negation
[44]
Compiler support
See also
References
- ↑ "N4661 Editors' Report -- Programming Languages -- C++". 21 March 2017. Retrieved 2017-03-21.
- ↑ "ISO/IEC DIS 14882: Programming Languages — C++" (PDF). Archived from the original (PDF) on 2017-03-25.
- ↑ Herb Sutter. "C++17 is formally approved".
- ↑ "ISO/IEC 14882:2017".
- ↑ https://herbsutter.com/2016/06/30/trip-report-summer-iso-c-standards-meeting-oulu/ "the next standard after C++17 will be C++20"
- ↑ "Current Status : Standard C++".
- ↑ "Trip Report: C++ Standards Meeting in Toronto, July 2017". 2 August 2017. Retrieved 11 January 2018.
- ↑ "N3981: Removing trigraphs??! (Richard Smith)". 2014-05-06.
- ↑ IBM comment on preparing for a Trigraph-adverse future in C++17, IBM paper N4210, 2014-10-10. Authors: Michael Wong, Hubert Tong, Rajan Bhakta, Derek Inglis
- 1 2 3 "Updates to my trip report".
- ↑ "N4190: Removing auto_ptr, random_shuffle(), And Old <functional> Stuff (Stephan T. Lavavej)".
- ↑ "N3928: Extending static_assert, v2 (Walter E. Brown)" (PDF).
- ↑ "N4051: Allow typename in a template template parameter (Richard Smith)".
- ↑ "N3922: New Rules for auto deduction from braced-init-list (James Dennett)".
- ↑ "N4230: Nested namespace definition (Robert Kawulak, Andrew Tomazos)".
- 1 2 3 4 5 "New core language papers adopted for C++17".
- ↑ "N4266: Attributes for namespaces and enumerators (Richard Smith)".
- ↑ "N4640: Working Draft, Standard for Programming Language C++" (PDF). pp. 193–195.
- ↑ "N4267: Adding u8 character literals (Richard Smith)".
- ↑ Thomas Köppe. "Hexadecimal floating literals for C++".
- ↑ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §5.13.4.
- ↑ "N4268: Allow constant evaluation for all non-type template arguments (Richard Smith)".
- ↑ "N4295: Folding expressions (Andrew Sutton, Richard Smith)".
- ↑ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §9.4.1.
- ↑ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §11.5.
- ↑ "Selection statements with initializer".
- ↑ "Dynamic memory allocation for over-aligned data".
- ↑ "N4640: Working Draft, Standard for Programming Language C++" (PDF). pp. 431–433.
- ↑ "C++ Keywords: register".
- ↑ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §19.8.
- ↑ "Adopt Library Fundamentals V1 TS Components for C++17 (R1)".
- ↑ "Current Status".
- ↑ "std::basic_string_view - cppreference.com". en.cppreference.com. Retrieved 2016-06-23.
- ↑ "N4259: Wording for std::uncaught_exceptions (Herb Sutter)" (PDF).
- ↑ "N4279: Improved insertion interface for unique-key maps (Thomas Köppe)".
- 1 2 3 "New standard library papers adopted for C++17".
- ↑ "N4280: Non-member size() and more (Riccardo Marcangelo)" (PDF).
- ↑ "N4284: Contiguous Iterators (Jens Maurer)".
- ↑ "Filesystem Library Proposal (Beman Dawes)".
- ↑ "The Parallelism TS Should be Standardized".
- ↑ "Mathematical Special Functions for C++17, v5" (PDF).
- ↑ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §23.7.
- ↑ "A byte type definition" (PDF).
- ↑ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §23.15.8.
- ↑ "C++ Standards Support in GCC - GNU Project - Free Software Foundation (FSF)". gcc.gnu.org.
- ↑ "Chapter 1. Status". gcc.gnu.org.
- ↑ "Clang - C++17, C++14, C++11 and C++98 Status". clang.llvm.org.
- ↑ corob-msft. "Visual C++ Language Conformance". docs.microsoft.com.
- ↑ "Announcing: MSVC Conforms to the C++ Standard".