Articles & Books

Erasing the Concrete -- K-ballo

Have you heard of "type erasure"?

Erasing the Concrete

by K-ballo

From the article:

Type erasure is any technique in which a single type can be used to represent a wide variety of types that share a common interface. In the C++ lands, the term type-erasure is strongly associated with the particular technique that uses templates in the interface and dynamic polymorphism in the implementation.

A union is the simplest form of type erasure.

  • It is bounded, and all participating types have to be mentioned at the point of declaration.

A void pointer is a low-level form of type erasure. Functionality is provided by pointers to functions that operate on void* after casting it back to the appropriate type.

  • It is unbounded, but type unsafe.

Virtual functions offer a type safe form of type erasure. The underlying void and function pointers are generated by the compiler.

  • It is unbounded, but intrusive.
  • Has reference semantics.

A template based form of type erasure provides a natural C++ interface. The implementation is built on top of dynamic polymorphism.

  • It is unbounded and unintrusive.
  • Has value semantics.

Two years of Meeting C++! -- Jens Weller

A lot has changed in just two years. Check this out for some visibility into the European C++ scene.

Two years of Meeting C++!

by Jens Weller

Note: Jens will be giving two talks at two talks at CppCon, including "Founding User Groups." He knows what he's talking about... from the article:

While I only know of 3 active User Groups around 2011/early 2012 (Oslo, Belgium & Düsseldorf), the active user Groups in Europe are a huge success, showing the popularity of C++: ... Also note, that I haven't listed active ACCU Groups, there exist a few in Great Britain, but I'm not sure when they started and how active they are. In total there currently 17 User Groups being active in 2014 or 2013.

C++11 Final Override -- 741MHz

A good article posted last year and making the rounds again this week:

C++11 Final Override

by 741MHz

From the article:

C++11 introduces two important keywords in relation to polymorphism and inheritance — the override and final. Using those keywords should become a habit of any C++ developer. It is worth using every time except when writing a base class. This will make the code clear, maintainable, and potentially save hours that would have been otherwise wasted chasing an error in debugger.

Quick Q: When are copy and move operations automatically generated? -- StackOverflow

Recently on SO:

What are the rules for automatic generation of move operations?

In C++98, the C++ compiler could automatically generate copy constructor and copy assignment operator via member-wise copy, e.g.

struct X {
    std::string s;
    std::vector<int> v;
    int n;
};

The compiler automatically generates copy constructor and copy assignment operator for X, using member-wise copy.

But how do things change in C++11 with move semantics?

Are the move constructor and move assignment operator automatically generated, like copy constructors and copy assignment operators?

Are there cases in which move operations are not automatically generated?

The Drawbacks of Implementing Move Assignment in Terms of Swap -- Scott Meyers

Hot off the Meyers press: How would you implement move, and why? Scott Meyers explains two related issues:

The Drawbacks of Implementing Move Assignment in Terms of Swap

by Scott Meyers

From the article:

More and more, I bump into people who, by default, want to implement move assignment in terms of swap. This disturbs me, because (1) it's often a pessimization in a context where optimization is important, and (2) it has some unpleasant behavioral implications as regards resource management.

Effective Modern C++ due October, preview in early July -- Scott Meyers

Scott Meyers' highly anticipated new book Effective Modern C++ is on the way:

Effective Modern C++ Status Report

by Scott Meyers

From the announcement:

In recent days, two major milestones for Effective Modern C++ have been achieved. First, I sent a draft of the book's Introduction out for technical review. That was the last part of the book to be written, so I finally have a full draft manuscript. Second, I received an image of the book cover from my publisher, so I now know what the book will look like.

...

  • Early October: Digital versions of the book become available.
  • Late October: Print versions of the book become available.

If you're dying to see what's in the book, and you don't mind dealing with a manuscript that's in draft form (and hence contains technical errors, awkward prose, Item titles in need of revision, primitive diagrams, confusing explanations, and, I hope, some stuff in decent shape), Effective Modern C++ will be part of O'Reilly's Early Release Program, meaning you'll have a chance to see the book in the same form as my technical reviewers. You'll also be able to offer comments on it. As things stand now, the book is slated to be available in Early Release form the week of July 7th.

Using variadic macros -- Andrzej Krzemieński

The latest from the desk of Andrzej:

Using variadic macros

by Andrzej Krzemieński

From the article:

But what struck me was something different. Why is it only some compilers that rejected my code. Why did most of the other compilers accept my apparently buggy code and produced the right result?

The answer is in the title of this post. Boost.StaticAssert is clever and wherever possible it uses variadic macros. ... it is now OK: all these arguments along with the separating commas are forwarded further (e.g., to static_assert) to the code that knows how to interpret these tokens. This is a very nice usage of variadic macros.

Masking a Class in Boost Graph, Part 3: Finding the Path -- Vadim Androsov

Part 3 of Vadim's experience report about using Boost's graph support in an existing game app:

Masking a Class in Boost Graph. Part 3: Finding the Path

by Vadim Androsov

From the article:

In the previous articles of the series we’ve reviewed the adaptive process of the square game field for concepts of boost graphs. Now we’ll consider the process of finding the path in the square field. Implementation of boost search allows adapting the algorithm quite accurately. In this article we’ll provide just one example of such parameterization – an ability to create various lengths of graph edges. ...