Blog

CppCon 2014 STL Features And Implementation Techniques—Stephan Lavavej

While we wait for CppCon 2015 in September, we’re featuring videos of some of the 100+ talks from CppCon 2014. Here is today’s feature:

STL Features And Implementation Techniques

by Stephan Lavavej

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

This session will cover selected STL features from C++11/14, both explaining how to use them and delving into implementation techniques that could be useful outside the STL.

I will avoid covering popular features you're already using (e.g. make_shared, make_unique) and obscure features of limited use (e.g. forward_list). The focus will be on useful but underappreciated features like dual-range algorithms, minimal allocators, and heterogeneous associative lookup.

Tippet: Use reference_wrapper to create views of data—Indi

Explicit C++ describes how to use std::reference_wrapper to create alternative views of data.

Tippet: Use reference_wrapper to create views of data

by Indi

from the article:

When working with objects indirectly, always use references. Only use pointers to indicate optional referencing. But there’s one little hitch: because you can’t rebind references, you can’t simply have a container of references. Enter std::reference_wrapper.

The C++ highlights and more of GCC 5.1

The release of GCC 5.1 is a highlight, here is an overview on the most important new things:

The C++ highlights of GCC 5.1 and more

by Jens Weller

From the article:

Just recently, GCC 5.0 has been released as GCC5.1, the not only the newest version of GCC, but also bumping up the version number from 4 to 5. This release is a major milestone for GCC, but also for C++, as it brings full C++14 support, but yet not C++11(std=c++11) as the new default...

CppCast Episode 9: Asynchronous Programming with Hartmut Kaiser

Episode 9 of CppCast the only podcast by C++ developers for C++ developers. In this episode Rob and Jason are joined by Hartmut Kaiser to talk about Asynchronous Program and the HPX framework.

CppCast Episode 9: Asynchronous Programming with Hartmut Kaiser

by Rob Irving and Jason Turner

About the interviewee:

Hartmut Kaiser is an Adjunct Professor of Computer Science at Louisiana State University. At the same time, he holds the position of a senior scientist at the Center for Computation and Technology at LSU. He received his doctorate from the Technical University of Chemnitz (Germany) in 1988. He is probably best known through his involvement in open source software projects, mainly as the author of several C++ libraries he has contributed to Boost, which are in use by thousands of developers worldwide. He is a voting member of the ISO C++ Standards Committee and his current research is focused on leading the STE||AR group at CCT working on the practical design and implementation of the ParalleX execution model and related programming methods. In addition, he architected and developed the core library modules of SAGA for C++, a Simple API for Grid Applications.

GCC 5.1 released

A new version of GCC is out, with a lot of improvements:

GCC 5.1 released

Some changes:

C++

  • G++ now supports C++14 variable templates.
  • -Wnon-virtual-dtor doesn't warn anymore for final classes.
  • Excessive template instantiation depth is now a fatal error. This prevents excessive diagnostics that usually do not help to identify the problem.
  • G++ and libstdc++ now implement the feature-testing macros from Feature-testing recommendations for C++.
  • G++ now allows typename in a template template parameter.
template<template<typename> typename X> struct D; // OK
  • G++ now supports C++14 aggregates with non-static data member initializers.
struct A { int i, j = i; };
A a = { 42 }; // a.j is also 42
  • G++ now supports C++14 extended constexpr.
constexpr int f (int i)
{
  int j = 0;
  for (; i > 0; --i)
    ++j;
  return j;
}
constexpr int i = f(42); // i is 42
  • G++ now supports the C++14 sized deallocation functions.
void operator delete (void *, std::size_t) noexcept;
void operator delete[] (void *, std::size_t) noexcept;
  • A new One Definition Rule violation warning (controlled by -Wodr) detects mismatches in type definitions and virtual table contents during link-time optimization.
  • New warnings -Wsuggest-final-types and -Wsuggest-final-methods help developers to annotate programs with final specifiers (or anonymous namespaces) to improve code generation. These warnings can be used at compile time, but they are more useful in combination with link-time optimization.
  • G++ no longer supports N3639 variable length arrays, as they were removed from the C++14 working paper prior to ratification. GNU VLAs are still supported, so VLA support is now the same in C++14 mode as in C++98 and C++11 modes.
  • G++ now allows passing a non-trivially-copyable class via C varargs, which is conditionally-supported with implementation-defined semantics in the standard. This uses the same calling convention as a normal value parameter.
  • G++ now defaults to -fabi-version=0 and -fabi-compat-version=2. So various mangling bugs are fixed, but G++ will still emit aliases with the old, wrong mangling where feasible. -Wabi continues to warn about differences.
libstdc++
  • A Dual ABI is provided by the library. A new ABI is enabled by default. The old ABI is still supported and can be used by defining the macro _GLIBCXX_USE_CXX11_ABI to 0 before including any C++ standard library headers.
  • A new implementation of std::string is enabled by default, using the small string optimization instead of copy-on-write reference counting.
  • A new implementation of std::list is enabled by default, with an O(1) size() function;
  • Full support for C++11, including the following new features:
    • std::deque and std::vector<bool> meet the allocator-aware container requirements;
    • movable and swappable iostream classes;
    • support for std::align and std::aligned_union;
    • type traits std::is_trivially_copyable, std::is_trivially_constructible, std::is_trivially_assignable etc.;
    • I/O manipulators std::put_time, std::get_time, std::hexfloat and std::defaultfloat;
    • generic locale-aware std::isblank;
    • locale facets for Unicode conversion;
    • atomic operations for std::shared_ptr;
    • std::notify_all_at_thread_exit() and functions for making futures ready at thread exit.
  • Support for the C++11 hexfloat manipulator changes how the num_put facet formats floating point types when ios_base::fixed|ios_base::scientific is set in a stream's fmtflags. This change affects all language modes, even though the C++98 standard gave no special meaning to that combination of flags. To prevent the use of hexadecimal notation for floating point types use str.unsetf(std::ios_base::floatfield) to clear the relevant bits in str.flags().
  • Full experimental support for C++14, including the following new features:
    • std::is_final type trait;
    • heterogeneous comparison lookup in associative containers.
    • global functions cbegin, cend, rbegin, rend, crbegin, and crend for range access to containers, arrays and initializer lists.
  • Improved experimental support for the Library Fundamentals TS, including:
    • class std::experimental::any;
    • function template std::experimental::apply;
    • function template std::experimental::sample;
    • function template std::experimental::search and related searcher types;
    • variable templates for type traits;
    • function template std::experimental::not_fn.
  • New random number distributions logistic_distribution and uniform_on_sphere_distribution as extensions.
  • GDB Xmethods for containers and std::unique_ptr.

Coupling and Cohesion—Paul Watt

coupling-lego.PNGA solid and entertaining treatment with good C++ examples:

Coupling and Cohesion

by Paul Watt

From the middle of the article:

... To further clarify this statement, not all code should be reused.

Why Not?

Because the majority of software that is written is designed to fulfill a very specific purpose. The challenge is to find the balance point between generic reusable building blocks, and a tool or application that meets a need. Generic software components are very valuable, however, they are almost useless by themselves...

And gems like this:

... For every statement of code that you write or use, you should ask the question: Does this add value or risk?

CppCon 2014 Exception-Safe Code, Part III—Jon Kalb

While we wait for CppCon 2015 in September, we’re featuring videos of some of the 100+ talks from CppCon 2014. Here is today’s feature:

Exception-Safe Code, Part III

by Jon Kalb

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

Are you 100% confident that your code is exception-safe?

Safe usage of exceptions is a non-trivial problem that the industry has struggled with for the better part of two decades. If you have fear, uncertainty, or doubt about exception safety or just want to see the best practices for using exceptions in C++ and/or C++11/14, this session is for you. We’ll start with “What is the problem we are trying to solve?” and discuss alternatives, acknowledge the challenges associated with exception usage, and cover some well-meaning but misguided attempts at safety. I will then present a set of guidelines that are the basis for safe exception usage and solid implementation techniques, including how to transition from an exception-unsafe legacy code base.

When we are finished you will know how to produce code that is easier to write, easier to understand, faster, and 100% robust in the face of exceptions.