Search

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.


C.1 -- The end?
Index
B.2 -- Introduction to C++14

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

  • hellmet

    Hello Alex and Nascardriver! I have an unrelated doubt.

    In cmake, I have a directory structure like so

    Adding a cmake file for each of the subfolders and adding libraries for each (ex: in each of Device, Instance etc...) and linking them into a RenderLib would be one way. The other way is to just glob all of the files under Render to build a single RenderLib. Which is a better approach? I was thinking, with the first approach, compilation would be streamlined, but then again, cmake knows which files change and can compile only those units required. So I don't think there is any performance advantage in glob vs lib-per-module. What would you suggest?

    • nascardriver

      If you're writing the files in Render/ (ie. they're still changing), compile them (Either in a separate CMakeLists or in one for the entire project). If Render/ is a project on its own, compile it to a library link to it.
      As you said, the files will only be compiled once either way. If Render/ is a project on its own and you copy the files to a different project to use them, you might end up with several copies of the source files each with some minor differences you made along the way.

      • hellmet

        Yeah I'm writing all of them. It's not a project itself though, but I could make it one, so it's reusable in anything else I make... Hmm... For now, I'm not making it a project by itself. So I thought, I'll just glob all the files under Render and export a RenderLib. That's fine right?

  • 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++ [https://www.reddit.com/r/learnprogramming/wiki/index#wiki_discouraged_resources].

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

    Thanks.

    • 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.

      Resources
      - https://www.reddit.com/r/learnprogramming/comments/4wbeg5/is_learncppcom_still_considered_bad/
      - https://www.reddit.com/r/learnprogramming/comments/6z8en4/why_is_learncppcom_a_discouraged_resource/
      - https://www.reddit.com/r/learnprogramming/comments/3ncs7q/c_learncppcom_has_been_updated_is_it_a_reliable/

    • 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. "
      https://en.wikipedia.org/wiki/International_Organization_for_Standardization#Name_and_abbreviations

  • 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]