B.3 — Introduction to C++17

What is C++17?

In September of 2017, the ISO (International Organization for Standardization) approved a new version of C++, called C++17. C++17 contains a fair amount of new content

New improvements in C++17

For your interest, here’s a list of the major improvements that C++17 adds. Note that this list is not comprehensive, but rather intended to highlight some of the key improvements of interest.

  • __has_include preprocessor identifier to check if optional header files are available (no tutorial yet)
  • if statements that resolve at compile time (no tutorial yet)
  • Initializers in if statements and switch statements (no tutorial yet)
  • inline variables (no tutorial yet)
  • Fold expressions (no tutorial yet)
  • Nested namespaces can now be defined as namespace X::Y (S.4.3b -- Namespaces)
  • Removal of std::auto_ptr and some other deprecated types
  • static_assert no longer requires a diagnostic text message parameter (7.12a -- Assert and static_assert)
  • std::any (no tutorial yet)
  • std::byte (no tutorial yet)
  • std::filesystem (no tutorial yet)
  • std::optional (no tutorial yet)
  • std::shared_ptr can now manage C-style arrays (but std::make_shared can’t create them yet) (15.6 -- std::shared_ptr)
  • std::size (6.2 -- Arrays (Part II))
  • Structured binding declarations (7.4a -- Returning values by value, reference, and address, but could use a full lesson)
  • Template deduction for constructors (no tutorial yet)
  • Trigraphs have been removed (no tutorial yet)
  • typename can now be used (instead of class) in a template template parameter (no tutorial yet)
  • UTF-8 (u8) character literals (no tutorial yet)
Appendix C -- The end?
B.2 -- Introduction to C++14

12 comments to B.3 — Introduction to C++17

  • Simon Allais

    There is also `std::variant` which is a C++17 template class representing type-safe union (useful when you simply want to use a "sum" type).

  • yoyos

    what will happen in C++20 and more? wil they continue to create new versions and keep people learning?

  • Soumya

    Hi Alex,

    I am a great fan of your website. But recently I saw in reddit that they discourage your site for learning C++ [].

    Actually I am worried and need your response to this. It would cleanse doubts in me and many others.


    • Hi Soumya!

      This has been discussed on said subreddit several times, I couldn't find a statement of a wiki maintainer.

      Summing it up:
      Some people don't like that Alex uses "wrong" names to explain certain topics. Though, throwing technical words and descriptions at a beginner is discouraging. As long as there's a transfer to the proper names once the basics are set, I don't see a problem.
      Some people don't like the order of the chapters/lessons, others do like the current order.
      There were and still are inconsistencies across all lessons, because the lessons weren't all written on the same day obviously. Alex fixes these inconsistencies once they are pointed out. One of the complaints was about @std::endl and '\n' being mixed. This has been addressed by Alex and mostly, if not entirely, been fixed.
      You'll have to go through a lot of lessons before you get to the topics that separate C and C++. Again, this can be considered good or bad.

      My opinion (I haven't read the lessons (apart from 2 or 3), I just reply to comments and give suggestions to learners):
      Learncpp is dated. Alex appears to be busy irl, so I can't blame him for not yet having lessons about C++14, 17 and 20. But there is too few content about C++11, and the content that is covered falls short compared to the pre C++11 content. eg. 9 lessons about C-style arrays and only 3 about @std::vector and @std::array,  @std::string not being properly discussed until chapter 17!
      A lot of quizzes involve writing algorithms, but Alex rarely mentions the @std functions that could be used instead (eg. @std::sort, @std::accumulate, @std::end, etc.). The @std library is too important to be left out.
      The first couple of lessons teach bad practice, some of which stretches throughout the entire tutorials (eg. std::endl and not using uniform initialization). All lessons should use the recommended features. The discouraged features should be discussed briefly, stating the difference to their alternatives and why they shouldn't be used.
      Adding rules but not following them in the tutorials causes readers the forget about the rules and don't follow them either.

      Despite these problem, I think of learncpp as the best place to learn C++.
      learncpp is actively maintained, questions get answered and errors get fixed. There are quizzes every couple of lessons which help understanding the lessons. C++ is a difficult language and Alex does a great job explaining it.


    • Rahul

      Things have been explained in a simple and easy way at this site. I have referred this website to many interns and young graduates in my team for a while, each one has come back that now they understand C++ better. I highly recommend this website to get foundation of C++ fundamentals right.

  • P-z

    2nd line:

      ISO (International Organization for Standardization)

    Shouldn't Organization and Standardization be flipped? Or IOS instead of ISO?

    • "ISO is not an acronym. The organization adopted ISO as its abbreviated name in reference to the Greek word isos (ίσος, meaning "equal"),[4] as its name in the three official languages would have different acronyms. "

  • nascardriver

    "Nested namespaces can now be defined as namespace X:Y"
    is missing a colon
    "Nested namespaces can now be defined as namespace X::Y"

Leave a Comment

Put all code inside code tags: [code]your code here[/code]