N4152: uncaught_exceptions -- Herb Sutter

A new WG21 paper is available. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N4152

Date: 2014-09-30

uncaught_exceptions

by Herb Sutter

Excerpt:

This paper is a revision of N3614 to implement EWG direction in Bristol.

...

This paper proposes a new function int std::uncaught_exceptions() that returns the number of exceptions currently active, meaning thrown or rethrown but not yet handled.

Insights into new and C++

I've written down some basic thinking on new and new standards:

Insights into new and C++

by Jens Weller

From the article:

Every now and then, I've been thinking about this. So this blogpost is also a summary of my thoughts on this topic, dynamic memory allocation and C++. Since I wrote the blog entries on smart pointers, and C++14 giving us make_unique, raw new and delete seem to disappear from C++ in our future code...

Quick Q: How can I call a function only one? -- StackOverflow

Quick A: std::call_once.

Recently on StackOverflow:

Standard library function for running a function only once

Is there some standard library function/class the behaviour of this lambda expression:

void some_func(int some_arg, float some_other_arg){
    static int do_once = ([](){
        // will be run once upon first function call but never again
        return 0; // dummy return value
    })();
    // will always run
}

t feels like such a hack to write this, but I can't think of another way of doing this other than simply calling the function in main, but what I'm actually doing depends upon template parameters and I need to keep it as generic as possible.

For context: I register a function with atexit for every different template parameter, but only once: the first time it is called.

GEANT4: Forecasting the future -- Monica Friedlander

A widely-used C++ program you might never have heard of: Physicists and other scientists use the GEANT4 toolkit to identify problems before they occur.

GEANT4: Forecasting the future

By Monica Friedlander

From the article:

Physicists can tell the future -- or at least foresee multiple possible versions of it. They do this through computer simulations. Simulations can help scientists predict what will happen when a particular kind of particle hits a particular kind of material in a particle detector. But physicists are not the only scientists interested in predicting how particles and other matter will interact. This information is critical in multiple fields, especially those concerned about the effects of radiation.

At CERN in 1974, scientists created the first version of GEANT (Geometry and Tracking) to help physicists create simulations. Today it is in its fourth iteration, developed by an international collaboration of about 100 scientists from 19 countries. Anyone can download the system to a personal computer, use C++ programming language to plug in details about the particle and material in question and find out what will happen when the two meet.

GEANT4 is used in some of the most advanced accelerator experiments in the world, but its user base has grown beyond the particle physics community...

Quick Q: Do smart pointers help replace raw pointers? -- StackOverflow

Quick A: Yes, smart pointers replace owning raw pointers, and you should prefer smart pointers in new code. Raw pointers and references are still appropriate to pass parameters down a stack.

Recently on SO:

C++ 11 Smart Pointer usage

I have a question about smart pointers in c++ 11. I've started to have a look at C++ 11 (I usualy program in c#) and read some thing about smart pointers. Now i have the question, does smart pointers completely replace the "old" style of pointers, should i always use them?

18 C++ User Group Meetings in October

The monthly overview on upcoming C++ User Group Meetings:

C++ User Group Meetings in October

by Jens Weller

From the article:

The monthly overview on the meetings of C++ User Groups world wide:

1.10 C++ UG Austin - Understanding and Using Generic Libraries in C++
2.10 C++ UG Paris - C++ FRUG #4 - C++ & Python
2.10 C++ UG New York - An Evening with Bjarne Stroustrup
2.10 C++ UG Madrid - De 0 a 100 (Taller)
2.10 C++ UG Istanbul - R-value references and Move Semantics
8.10 C++ UG San Francisco/ Bay area - Presentation and Q&A
9.10 C++ UG Dresden - Build Systems
11.10 C++ UG Pune, India - A hands-on introduction to the Boost Libraries
15.10 C++ UG Montpellier - Rencontre C++
15.10 C++ UG Düsseldorf - Coding Dojo
15.10 C++ UG Santa Barbara - Kickoff meeting
16.10 C++ UG Seattle/North West - Compiler Technologies
20.10 C++ UG Denver - Coding Dojo
21.10 C++ UG Berlin - No topic yet.
22.10 C++ UG Hamburg - Einführung in MPI
22.10 C++ UG San Francisco/ Bay area - Workshop and Discussion Group
23.10 C++ UG Bristol - "Lessons From Test Code" with Jon Jagger
25.10 C++ UG Saratov, Russia
29.10 C++ UG London - No topic yet.

And In the Beginning... -- Tony DaSilva

We don't normally link to pleas to spam mass-email anyone, never mind Bjarne Stroustrup, but we just had to share this heartfelt plea because it would be Good for the World. (Sorry, Dr. Stroustrup!)

But even if you don't email him, read or re-read D&E. It's still quite current.

And In the Beginning...

by Tony DaSilva

From the article:

I’m on my second pass through Bjarne Stroustrup’s "The Design And Evolution Of C++". In the book...

CppCon 2014 videos online

From the CppCon blog:

2014 Videos Online

We are announcing the CppCon Channel on YouTube with the first uploads of our video from CppCon 2014.

Our first videos feature our three keynote presentations from Bjarne Stroustrup, Mark Maimone, and Mike Acton; as well as our opening and closing plenary sessions from Scott Meyers and Herb Sutter. 

Over the next few weeks we’ll be uploading videos of most of the conference sessions including panels, lightning talks, and over one hundred sessions from the six tracks that made up the core of our conference program. The first two of our regular session uploads are from Michael Caisse and Thomas Rodgers.

We’d like to thank the speakers for allowing these sessions to be recorded and shared and Bash Films for the production of these videos.

Quick Q: Why can noexcept generate faster code than throw()? -- StackOverflow

Quick A: Because noexcept doesn't have to keep track of stack unwinding.

noexcept, stack unwinding, and performance

The following draft from Scott Meyers new C++11 book says (page 2, lines 7-21)

The difference between unwinding the call stack and possibly unwinding it has a surprisingly large impact on code generation. In a noexcept function, optimizers need not keep the runtime stack in an unwindable state if an exception would propagate out of the function, nor must they ensure that objects in a noexcept function are destroyed in the inverse order of construction should an exception leave the function. The result is more opportunities for optimization, not only within the body of a noexcept function, but also at sites where the function is called. Such flexibility is present only for noexcept functions. Functions with “throw()” exception specifications lack it, as do functions with no exception specification at all.

In contrast, section 5.4 of "Technical Report on C++ Performance" describes the "code" and "table" ways of implementing exception handling. In particular, the "table" method is shown to have no time overhead when no exceptions are thrown and only has a space overhead.

My question is this - what optimizations is Scott Meyers talking about when he talks of unwinding vs possibly unwinding? Why don't these optimizations apply for throw()? Do his comments apply only to the "code" method mentioned in the 2006 TR?