C++17

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

C++17 is a revision of the ISO/IEC 14882 standard for the C++ programming language. As of 2019, this is the most recent revision, while the successor C++20[1][2][3] is under preparation.

History[edit]

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.[4][5] This DIS was unanimously approved, with only editorial comments,[6] and the final standard was published in December 2017.[7] 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.

Removed[edit]

This revision of C++ not only added new features but also removed a few.

  • Removal of trigraphs.[8][9]
  • Removal of some deprecated types and functions from the standard library, including std::auto_ptr, std::random_shuffle, and old function adaptors.[10][11] These were superseded in C++11 by improved facilities such as std::unique_ptr, std::shuffle, std::bind, and lambdas.
  • Removal of the (formerly deprecated) use of the keyword register as a storage class specifier.[12] This keyword is now reserved and unused.

New features[edit]

C++17 introduced many new features. The following lists may be incomplete.

Language[edit]

  • Making the text message for static_assert optional[13]
  • Allow typename (as an alternative to class) in a template template parameter[14]
  • New rules for auto deduction from braced-init-list[15][10]
  • Nested namespace definitions, e.g., namespace X::Y { } instead of namespace X { namespace Y { } }[10][16]
  • Allowing attributes for namespaces and enumerators[17][18]
  • New standard attributes [[fallthrough]], [[maybe_unused]] and [[nodiscard]][19]
  • UTF-8 (u8) character literals[17][20] (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[21][22]
  • Constant evaluation for all non-type template arguments[17][23]
  • Fold expressions, for variadic templates[17][24]
  • A compile-time static if with the form if constexpr(expression)[25]
  • Structured binding declarations, allowing auto [a, b] = getTwoReturnValues();[26]
  • Initializers in if and switch statements[27]
  • copy-initialization and direct-initialization of objects of type T from prvalue expressions of type T (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[28]
  • Class template argument deduction (CTAD), introducing constructor deduction guides, eg. allowing std::pair(5.0, false) instead of requiring explicit constructor arguments types std::pair<double, bool>(5.0, false) or an additional helper template function std::make_pair(5.0, false).[29][30]
  • 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[31]
  • Value of __cplusplus changed to 201703L[32]
  • Exception specifications were made part of the function type[33]

Library[edit]

Compiler support[edit]

  • GCC since version 7 has complete support for C++17.[48]
  • Clang 5 and later implement all the features of C++17.[49]
  • Visual Studio 2017 15.7 (MSVC 19.14) supports almost all of C++17.[50][51]

Library support[edit]

  • libstdc++ since version 9.1 has complete support for c++17 (8.1 without Parallelism TS and referring to C99 instead of C11) [52]
  • libc++ as of version 9 has partial support for c++17, with the remainder "in progress" [53]
  • MSVC Standard Library since 19.15 complete support for c++17 except for "Elementary String Conversions" and referring to C99 instead of C11.[54]

See also[edit]

References[edit]

  1. ^ https://herbsutter.com/2016/06/30/trip-report-summer-iso-c-standards-meeting-oulu/ "the next standard after C++17 will be C++20"
  2. ^ "Current Status : Standard C++".
  3. ^ "Trip Report: C++ Standards Meeting in Toronto, July 2017". 2 August 2017. Retrieved 11 January 2018.
  4. ^ "N4661 Editors' Report -- Programming Languages -- C++". 21 March 2017. Retrieved 2017-03-21.
  5. ^ "ISO/IEC DIS 14882: Programming Languages — C++" (PDF). Archived from the original (PDF) on 2017-03-25.
  6. ^ Herb Sutter. "C++17 is formally approved".
  7. ^ "ISO/IEC 14882:2017".
  8. ^ "N3981: Removing trigraphs??! (Richard Smith)". 2014-05-06.
  9. ^ 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
  10. ^ a b c "Updates to my trip report".
  11. ^ "N4190: Removing auto_ptr, random_shuffle(), And Old <functional> Stuff (Stephan T. Lavavej)".
  12. ^ "C++ Keywords: register".
  13. ^ "N3928: Extending static_assert, v2 (Walter E. Brown)" (PDF).
  14. ^ "N4051: Allow typename in a template template parameter (Richard Smith)".
  15. ^ "N3922: New Rules for auto deduction from braced-init-list (James Dennett)".
  16. ^ "N4230: Nested namespace definition (Robert Kawulak, Andrew Tomazos)".
  17. ^ a b c d e "New core language papers adopted for C++17".
  18. ^ "N4266: Attributes for namespaces and enumerators (Richard Smith)".
  19. ^ "N4640: Working Draft, Standard for Programming Language C++" (PDF). pp. 193–195.
  20. ^ "N4267: Adding u8 character literals (Richard Smith)".
  21. ^ Thomas Köppe. "Hexadecimal floating literals for C++".
  22. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §5.13.4.
  23. ^ "N4268: Allow constant evaluation for all non-type template arguments (Richard Smith)".
  24. ^ "N4295: Folding expressions (Andrew Sutton, Richard Smith)".
  25. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §9.4.1.
  26. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §11.5.
  27. ^ "Selection statements with initializer".
  28. ^ "Dynamic memory allocation for over-aligned data".
  29. ^ "Class template argument deduction".
  30. ^ "CppCon 2018: Timur Doumler "Class template argument deduction in C++17"".
  31. ^ "N4640: Working Draft, Standard for Programming Language C++" (PDF). pp. 431–433.
  32. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §19.8.
  33. ^ "P0012R1: Make exception specifications be part of the type system, version 5".
  34. ^ "Adopt Library Fundamentals V1 TS Components for C++17 (R1)".
  35. ^ "Current Status".
  36. ^ "std::basic_string_view - cppreference.com". en.cppreference.com. Retrieved 2016-06-23.
  37. ^ "N4259: Wording for std::uncaught_exceptions (Herb Sutter)" (PDF).
  38. ^ "N4279: Improved insertion interface for unique-key maps (Thomas Köppe)".
  39. ^ a b c "New standard library papers adopted for C++17".
  40. ^ "N4280: Non-member size() and more (Riccardo Marcangelo)" (PDF).
  41. ^ "N4284: Contiguous Iterators (Jens Maurer)".
  42. ^ "Filesystem Library Proposal (Beman Dawes)".
  43. ^ "The Parallelism TS Should be Standardized".
  44. ^ "Mathematical Special Functions for C++17, v5" (PDF).
  45. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §23.7.
  46. ^ "A byte type definition" (PDF).
  47. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §23.15.8.
  48. ^ "C++ Standards Support in GCC - GNU Project - Free Software Foundation (FSF)". gcc.gnu.org.
  49. ^ "Clang - C++17, C++14, C++11 and C++98 Status". clang.llvm.org.
  50. ^ corob-msft. "Visual C++ Language Conformance". docs.microsoft.com.
  51. ^ "Announcing: MSVC Conforms to the C++ Standard".
  52. ^ "Chapter 1. Status". gcc.gnu.org.
  53. ^ "libc++ C++17 Status". llvm.org.
  54. ^ "Announcing: MSVC Conforms to the C++ Standard". devblogs.microsoft.com.