XL C/C++ V11.1 supports extern templates, enum class, right angle brackets -- IBM C/C++ Cafe

[Ed.: We're pleased to report continued progress toward conformance by C++ compiler vendors. This post combines three features contributed by Cecilia, christineli, and Alice Ying]

The IBM XL C/C++ V11.1 now supports several new C++11 features.

With extern templates, you can provide an explicit instantiation declaration for a template specialization if an explicit instantiation definition of the template exists in other translation units or later in the same file. If one translation unit contains the explicit instantiation definition, other translation units can use the specialization without having the specialization instantiated multiple times.

With right angle brackets, you can avoid having to write an extra space in code like vector<list<int> >, and just write vector<list<int>> the way Stroustrup intended. 

With scoped enumerations, you can avoid the following problems with the traditional enumerations:

  • Implicit conversion to an integer
  • Inability to specify the underlying type
  • Scope issue: enumerator is injected into (a.k.a. "pollutes") the enclosing scope

Enjoy!

noexcept Destructors -- Andrzej Krzemieński

A slight change from C++98 to C++11, tightening up destructor semantics. Yes, it's still considered a best practice to never allow an exception to escape from a destructor -- in any language with destructor or Dispose functionality -- and now we have an additional reason in C++11:

noexcept Destructors

by Andrzej Krzemieński

From the article:

The goal of this post is to show one — fairly small — backwards incompatibility in C++11. It shows how noexcept exception specifications are implicitly generated for your destructors. In short, the following program used to run successfully in C++03 (under some definition of “success”): ...

In this post I do not intend to argue whether it is a bad practice or not to throw from destructors, but focus on what happens when you do. But I really do not encourage you to throw from destructors...

GotW #7a Solution: Minimizing Compile-Time Dependencies, Part 1—Herb Sutter

The solution to the latest GotW problem is now available. In this Item, the focus is on analyzing and managing compile-time dependencies.

    GotW #7a Solution: Minimizing Compile-Time Dependencies, Part 1

    by Herb Sutter

From the article:

Managing dependencies well is an essential part of writing solid code. C++ supports two powerful methods of abstraction: object-oriented programming and generic programming. Both of these are fundamentally tools to help manage dependencies, and therefore manage complexity. It’s telling that all of the common OO/generic buzzwords—including encapsulation, polymorphism, and type independence—along with most design patterns, are really about describing ways to manage complexity within a software system by managing the code’s interdependencies.

When we talk about dependencies, we usually think of run-time dependencies like class interactions. In this Item, we will focus instead on how to analyze and manage compile-time dependencies. As a first step, try to identify (and root out) unnecessary headers.

Guideline: Never #include unnecessary header files.

Guideline: Prefer to #include <iosfwd> when a forward declaration of a stream will suffice.

Guideline: Never #include a header when a forward declaration will suffice.

Continue reading...

Resumable Functions: async and await -- Jens Weller

JensWeller_small-da9313ea.jpgA look at resumable functions:

Resumable Functions: async and await

by Jens Weller

From the article:

While I did my series about the papers for Bristol, there was one paper, which I personally found a bit weird. This paper was about resumable functions, and at that time it was just another paper full of ideas for C++ to me. At C++Now suddenly, I got a better insight to what the use of resumable functions could be...

C++ String to Int -- Ivan Neeson

kumobius.PNGA nice comparison on converting a string to int:

C++ String to Int

by Ivan Neeson

From the article:

In this post I will compare the following methods for parsing a string into an integer in C++:

  • Manually
  • atoi()
  • strtol()
  • sscanf()
  • std::stoi (C++11 only)
  • std::istringstream
  • Boost.LexicalCast
  • Boost.LexicalCast with C locale
  • Boost.Spirit.Qi
  • Boost.Coerce

But first lets look at the requirements...

Overload 116 available

overload-116.PNGOverload 116 is now available. It contains the following articles, and more:

 

Overload 116

Auto -- A Necessary Evil? Part 2 -- Roger Orr

When is the use of auto good, and when is it evil?

Dynamic C++, Part 2 -- Alex Fabijanic

Alex Fabijanic and Richard Saunders continue to explore dynamic solutions in C++.

Portable String Literals in C++ -- Alf Steinbach

How hard can it be to make a file in C++ with international text literals in its name? Alf Steinbach shows us how to write a file called π.recipe.

Hard Upper Limit on Memory Latency -- Sergey Ignatchenko

How low can latency really get?

 

... and more!

An Important Move Optimization Is Nearly Invisible -- Andrew Koenig

Today in Dr. Dobb's:

An Important Move Optimization Is Nearly Invisible

by Andrew Koenig

From the article:

Last week, we looked at subtle differences between copying and moving a container (a string in this example) in the context of passing arguments to functions. Curiously, one of the biggest differences between copying and moving happens in code that we don't write. ...

The improvements in robustness and functionality that stem from moving instead of copying are, in my view, at least as important as the optimization. ...

GotW #94 Solution: AAA Style (Almost Always Auto) -- Herb Sutter

The solution to the latest GotW problem is now available:

GotW #94 Solution: AAA Style (Almost Always Auto)

by Herb Sutter

From the article:

4. When declaring a new local variable x, what advantages are there to declaring it using auto and one of the two following syntaxes:

(a) auto x = init; when you don’t need to commit to a specific type? (Note: The expression init might include calling a helper that performs partial type adjustment, such as as_signed, while still not committing to a specific type.)

(b) auto x = type{ init }; when you do want to commit to a specific type by naming a type?