September 2014

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?

Fun with C++14 Lambdas at Silicon Valley Code Camp -- Sumant Tambe

If you're going to SVCC'14, check out the C++ sessions:

Fun with C++14 Lambdas at Silicon Valley Code Camp

by Sumant Tambe

From the article:

Believe it or not, but the 9th Silicon Valley Code Camp is less than 2 weeks away and I can't wait to be at the largest software technology conference setup by developers for developers -- and here is the best part -- at no cost to the attendees. So far, there are 234 registered sessions, 7 technical tracks, and over 3100 registrations. So mark your calendar -- it's October 11th and 12th, Saturday and Sunday, as always.

C++ is hot again at SVCC and third year in a row there is a dedicated track for modern C++...

Variadic Templates -- Feabhas

variadic-templates.PNGRecently on StickyBits, a nice primer on variadics:

Variadic Templates

by feabhas

From the article:

In this article we’re going to look at a new feature of templates in C++11 -- the concept of the variadic template.

Variadic templates allow us to create functions and classes, not only with generic types, but also a variable number of generic types.

If you haven’t been following along with the template articles, I’d suggest you read this article first before continuing.

A Grand Introduction: Stepanov introduces Stroustrup at CppCon -- Tony DaSilva

Bulldozer00's appreciation for Alex Stepanov's introduction for Bjarne Stroustrup at CppCon. We already linked to the video last week -- but if you didn't watch it then, do yourself a favor and spend 6 minutes now getting your workweek off to a great start.

A Grand Introduction

by Tony DaSilva

From the article:

"We should not be ashamed of bits. We should be proud of them." -- Alex Stepanov

You may not interpret it in the same way as I did, but I found this cppcon conference introduction of Bjarne Stroustrup by programming scholar Alex Stepanov very moving...

N4149: Categorically qualified classes -- David Krauss

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: N4149

Date: 2014-09-25

Categorically qualified classes

by David Krauss

Excerpt:

Some classes only work in certain contexts: scope guards are usually useless as subexpressions, and expression template placeholders malfunction as local variables. An unused function result may signal that the caller intends to follow a different protocol, such as with std::async. This proposal extends class definitions to prevent such errors, and adds a mechanism to automatically resolve them by type substitution, such as a value type for an expression template. Additionally, generation of non-movable objects becomes more tractable.

The added functionality includes that of the “auto evaluation” proposals [1]. This proposal intends to be more expressive, more broadly applicable, and easier to adopt and use.

N4148: Disallowing Inaccessible Operators From Trivially Copyable -- Matheus Izvekov

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: N4148

Date: 2014-09-24

Disallowing Inaccessible Operators From Trivially Copyable

by Matheus Izvekov

Excerpt:

This proposal aims to solve a serious flaw in the definition of the trivially copyable concept. Presently, classes with deleted or inaccessible copy/move constructors, copy/move assignment operators and destructor are allowed to be trivially copyable, which might seem counterintuitive.

N4147: Inline variables, or encapsulated expressions -- David Krauss

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: N4147

Date: 2014-09-25

Inline variables, or encapsulated expressions

by David Krauss

Excerpt:

Inline functions have favorable behavior for interfaces which cannot be exposed as objects. Often, users are encouraged to use them to wrap global variables, despite unnatural boilerplate. Other workarounds include class static data members, enumerators, macros, and variable templates, all with awkward syntax or downsides and limited applicability. This proposal defines the inline specifier on variable definitions to indicate semantics similar to inline function evaluation and linkage. More generally, this produces a facility for named values, or variables without persistence, which may supersede or complement the various workarounds.

N4146: Disposition of Comments, ISO/IEC DIS 14882, C++ 2014 -- Barry Hedquist

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: N4146

Date: 2014-09-23

Disposition of Comments, ISO/IEC DIS 14882, C++ 2014

by Barry Hedquist

Excerpt:

Attached is WG21 N4146, the Disposition of Comments for ISO/IEC DIS 14882, Draft Information Standard ISO/IEC 14882:2014.

Document numbers referenced in the ballot comments are WG21 documents unless otherwise stated.

N4133: Cleanup for exception-specification and throw-expression -- Jens Maurer

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: N4133

Date: 2014-09-10

Cleanup for exception-specification and throw-expression

by Jens Maurer

Excerpt:

This paper proposes to adjust the wording for exceptions to achieve the following goals:

  • Exception specifications as a semantic concept are separated from the grammar term exception-specification
  • The description of throw-expression is integrated into clause 5.

The changes are intended to be editorial only, not changing semantics. Due to the size of the changes, it seems prudent to have a full CWG review for these instead of leaving the issue to the project editor alone.
 

N4132: Contiguous Iterators -- Jens Maurer

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: N4132

Date: 2014-09-10

Contiguous Iterators

by Jens Maurer

Excerpt:

There are four containers in the standard library that guarantee contiguous storage: vector, string, valarray, and array. In the Library Fundamentals TS, there is also string_view. This paper introduces the term "contiguous iterator" as a refinement of random-access iterator, without introducing a corresponding contiguous_iterator_tag, which was found to break code during the Issaquah discussions of Nevin Liber's paper N3884 "Contiguous Iterators: A Refinement of Random Access Iterators".