C++ Insights - Episode 21: How noexcept works

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ • 18

  • @MarcosCpp
    @MarcosCpp Місяць тому +2

    I liked this video, quick and straight to the point

  • @serhiymalokhatko
    @serhiymalokhatko Рік тому +2

    Does it mean that compiler generates extra code to handle this situation, and `noexcept` function can be larger/slower than `noexcept(false)`?

  • @tomkirbygreen
    @tomkirbygreen 6 місяців тому +1

    Very useful. Seems like it’s far from zero cost. Does noexcept get used much in (semi) realtime systems?

    • @andreas_fertig
      @andreas_fertig  5 місяців тому +1

      Your move-constructors and move-assignment operators are typically noexcept. That's the reason why we have noexcept in the first place.

  • @TheMR-777
    @TheMR-777 2 роки тому +3

    Now I got it! Thanks a lot for sharing this info :)

  • @niyazijackson
    @niyazijackson 2 роки тому +2

    Awesome. wouldnt it be nice if a handler could be passed into noexcept to be called in catch scope, instead of calling std::terminate().

    • @AlfredoCorrea
      @AlfredoCorrea 11 місяців тому

      not exactly the same, but in C++ you can customize what terminate does.

  • @panjak323
    @panjak323 5 місяців тому

    So why isn't noexcept the default?

    • @andreas_fertig
      @andreas_fertig  5 місяців тому +1

      Well, because it was introduced a long time after C++98. In addition it is a save default. Once you start throwing exceptions which pass functions which are noexcept default things get hard.

  • @concienciaconectiva
    @concienciaconectiva 2 роки тому

    What is AST?

    • @andreas_fertig
      @andreas_fertig  Рік тому +1

      Sorry, AST stands for abstract syntax tree. Here is the Wikipedia page explaining AST: en.wikipedia.org/wiki/Abstract_syntax_tree

  • @AlfredoCorrea
    @AlfredoCorrea Рік тому

    I don’t get it, the compiler can demonstrate that the body of the function will not be able to throw, so it will not contemplate calling terminate. So the code will be optimal in this case anyway. This video gives the opposite impression because it doesn’t say that all this will be optimized. I think the problem is when you say no except and you are calling a function that the compiler cannot demonstrate it cannot throw. In this case the compiled code generated will generate the call to terminate. I heard that there was an old argument in the committee and there was a faction (Abrahams?) that wanted plain UB for uncatched throwing inside noexcept and the other wanted a guaranteed call to terminate. The second faction won but there were some regrets afterwards.

    • @andreas_fertig
      @andreas_fertig  11 місяців тому +1

      There is no guarantee that an optimizer must do a particular optimization. This simple example compiler-explorer.com/z/TGeWcxrcf leads to code the compiler cannot efficiently optimize even though Other could simply return 2.

  • @JustABigFan2010
    @JustABigFan2010 9 місяців тому +7

    Andrea 99% of the surface area of your video content is blank. And the most important parts of your video is in the top left corner which is only 1% of the area. Would you please on your next videos kind of focus on that 1%. Either make the font larger so that it kind of becomes the 50% of the video surface area. A lot of people with huge monitors make this mistake. We don't need to see the useless 99% of the blank area. For the people too comfortably see that 1% of the surface area they will need to buy large monitors same as you. So watching this video on a 15 inch PC monitor a tablet or a phone is basically useless because you cannot even Zoom in on UA-cam videos.

    • @phusicus_404
      @phusicus_404 8 місяців тому

      You can zoom a video on UA-cam on a phone.

    • @JustABigFan2010
      @JustABigFan2010 8 місяців тому +1

      @@phusicus_404 Write and we love reading source code on a 6 inch phone screen. Besides do you think the quality when you zoom in is going to be good enough to understand anything that you're reading in the source code. Don't be silly.

  • @rinket7779
    @rinket7779 3 роки тому +1

    amazing vid! thanks so much!

  • @ЮрійГордієнко-х2з
    @ЮрійГордієнко-х2з 9 місяців тому

    Wrong