Open main menu

Wikipedia β

C++17 is the name for the most recent revision of the ISO/IEC 14882 standard for the C++ programming language.

Contents

HistoryEdit

When the release date was still uncertain, this 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]

Next standardEdit

Removed featuresEdit

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]

New featuresEdit

C++17 introduces many new features. The following lists may not be complete.

LanguageEdit

  • Making the text message for static_assert optional[12]
  • Allow typename (as an alternative to class) in a template template parameter[13]
  • Nested namespace definitions, e.g., namespace X::Y { … } instead of namespace 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]
  • Constant evaluation for all non-type template arguments[16][22]
  • Fold expressions, for variadic templates[16][23]
  • A compile-time static if with the form if constexpr(expression)[24]
  • Structured binding declarations, allowing auto [a, b] = getTwoReturnValues();[25]
  • Initializers in if and switch statements[26]
  • 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.
  • Some extensions on over-aligned memory allocation[27]
  • Template deduction of constructors, allowing std::pair(5.0, false) instead of std::pair<double,bool>(5.0, false)
  • Inline variables, which allows the definition of variables in header files
  • __has_include, allowing the availability of a header to be checked by preprocessor directives[28]
  • Value of __cplusplus changed to 201703L[29]

LibraryEdit

  • Most of Library Fundamentals TS I, including:[30][31]
    • std::string_view, a read-only non-owning reference to a character sequence or string-slice[32]
    • std::optional, for representing optional objects
    • std::any, for holding single values of any type
  • std::uncaught_exceptions, as a replacement of std::uncaught_exception[33][16]
  • New insertion functions try_emplace and insert_or_assign for std::map and std::unordered_map [34][35]
  • Uniform container access: std::size, std::empty and std::data[35][36]
  • Definition of "contiguous iterators"[35][37]
  • A file system library based on boost::filesystem[38]
  • Parallel versions of STL algorithms[39]
  • Logical operator traits: std::conjunction, std::disjunction and std::negation[43]

Compiler supportEdit

  • GCC 8 has complete (but experimental) support for C++17.[44][45]
  • Clang 5 and later implement all the features of C++17.[46]
  • Visual Studio 2017 15.7 (MSVC 19.14) supports almost all of C++17.[47][48]

See alsoEdit

ReferencesEdit

  1. ^ "N4661 Editors' Report -- Programming Languages -- C++". 21 March 2017. Retrieved 2017-03-21. 
  2. ^ "ISO/IEC DIS 14882: Programming Languages — C++" (PDF). Archived from the original (PDF) on 2017-03-25. 
  3. ^ Herb Sutter. "C++17 is formally approved". 
  4. ^ "ISO/IEC 14882:2017". 
  5. ^ https://herbsutter.com/2016/06/30/trip-report-summer-iso-c-standards-meeting-oulu/ "the next standard after C++17 will be C++20"
  6. ^ "Current Status : Standard C++". 
  7. ^ "Trip Report: C++ Standards Meeting in Toronto, July 2017". 2 August 2017. Retrieved 11 January 2018. 
  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. ^ "N3928: Extending static_assert, v2 (Walter E. Brown)" (PDF). 
  13. ^ "N4051: Allow typename in a template template parameter (Richard Smith)". 
  14. ^ "N3922: New Rules for auto deduction from braced-init-list (James Dennett)". 
  15. ^ "N4230: Nested namespace definition (Robert Kawulak, Andrew Tomazos)". 
  16. ^ a b c d e "New core language papers adopted for C++17". 
  17. ^ "N4266: Attributes for namespaces and enumerators (Richard Smith)". 
  18. ^ "N4640: Working Draft, Standard for Programming Language C++" (PDF). pp. 193–195. 
  19. ^ "N4267: Adding u8 character literals (Richard Smith)". 
  20. ^ Thomas Köppe. "Hexadecimal floating literals for C++". 
  21. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §5.13.4. 
  22. ^ "N4268: Allow constant evaluation for all non-type template arguments (Richard Smith)". 
  23. ^ "N4295: Folding expressions (Andrew Sutton, Richard Smith)". 
  24. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §9.4.1. 
  25. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §11.5. 
  26. ^ "If statement with initializer". 
  27. ^ "Dynamic memory allocation for over-aligned data". 
  28. ^ "N4640: Working Draft, Standard for Programming Language C++" (PDF). pp. 431–433. 
  29. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §19.8. 
  30. ^ "Adopt Library Fundamentals V1 TS Components for C++17 (R1)". 
  31. ^ "Current Status". 
  32. ^ "std::basic_string_view - cppreference.com". en.cppreference.com. Retrieved 2016-06-23. 
  33. ^ "N4259: Wording for std::uncaught_exceptions (Herb Sutter)" (PDF). 
  34. ^ "N4279: Improved insertion interface for unique-key maps (Thomas Köppe)". 
  35. ^ a b c "New standard library papers adopted for C++17". 
  36. ^ "N4280: Non-member size() and more (Riccardo Marcangelo)" (PDF). 
  37. ^ "N4284: Contiguous Iterators (Jens Maurer)". 
  38. ^ "Filesystem Library Proposal (Beman Dawes)". 
  39. ^ "The Parallelism TS Should be Standardized". 
  40. ^ "Mathematical Special Functions for C++17, v5" (PDF). 
  41. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §23.7. 
  42. ^ "A byte type definition" (PDF). 
  43. ^ "N4659: Working Draft, Standard for Programming Language C++" (PDF). §23.15.8. 
  44. ^ https://gcc.gnu.org/projects/cxx-status.html
  45. ^ https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html
  46. ^ https://clang.llvm.org/cxx_status.htm
  47. ^ https://docs.microsoft.com/en-us/cpp/visual-cpp-language-conformance
  48. ^ https://blogs.msdn.microsoft.com/vcblog/2018/05/07/announcing-msvc-conforms-to-the-c-standard/