advanced

Simple C++11 metaprogramming--Peter Dimov

If you like to play with templates, read this article:

Simple C++11 metaprogramming

by Peter Dimov

From the article:

The wide acceptance of Boost.MPL made C++ metaprogramming seem a solved problem. Perhaps MPL wasn't ideal, but it was good enough to the point that there wasn't really a need to seek or produce alternatives.

C++11 changed the playing field. The addition of variadic templates with their associated parameter packs added a compile-time list of types structure directly into the language...

Holier Than Thou--Tony “Bulldozer00” (BD00) DaSilva

A rare but possible problem that can occur with long running programs:

Holier Than Thou

by Tony DaSilva

From the article:

Since C++ (by deliberate design) does not include a native garbage collector or memory compactor, programs that perform dynamic memory allocation and de-allocation (via explicit or implicit use of the “new” and “delete” operators) cause small “holes” to accumulate in the free store over time. I guess you can say that C++ is “holier than thou“. :( ...

How to implement a stateful meta-container in C++ -- Filip Roséen

Implementing stateful meta contianer in C++ Using Modern C++.

How to implement a stateful meta-container in C++

by Filip Roséen

From the article:

This post has explained the technical aspects related to an implementation of a stateful meta-container, allowing a developer to more easily work with, and modify, a given set of entities during the phase of translation.

Together with the previous posts in this series, the formerly unstateful world of translation has gone into a stateful universe — allowing for some crazy, but conforming, implementations.

CppCon 2014 Sanitize your C++ code--Kostya Serebryany

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:

Sanitize your C++ code

by Kostya Serebryany

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

"Sanitizers" is a family of dynamic testing tools built into C++ compilers (Clang and GCC):
AddressSanitizer finds memory errors, such as use-after-free, buffer overflows, and leaks;
ThreadSanitizer finds data races, deadlocks, and other threading bugs;
MemorySanitizer finds uses of uninitialized memory;
UndefinedBehaviorSanitizer finds other kinds of undefined behavior, such as use of incorrect dynamic type, shift by illegal amount and many others.
You will learn how these tools work, how to use them on small programs and how we deploy them in large projects.

CppCon 2014 Large-Scale Refactoring @ Google--Hyrum Wright

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:

Large-Scale Refactoring @ Google

by Hyrum Wright

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

Many organizations have significant investments in a large existing C++ codebase, and Google is no exception. Our code is intended to survive for decades, but continue to track new language standards as they emerge. To do so, we have developed tools and techniques which provide the ability to automatically refactor code to use new APIs as they become available.

In this talk, I'll discuss some of the reasons for doing migrations that impact hundreds of thousands of files, and how we do them at Google, using tools such as ClangMR. I'll give examples, such as our recent migration to the standardized std::unique_ptr and std::shared_ptr types and lessons we've learned from these experiences. Finally, I'll point out pitfalls others may face in doing similar work, and suggest ways that they can be avoided.

CppCon 2014 Defensive Programming Done Right, Part II--John Lakos

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:

Defensive Programming Done Right, Part II

by John Lakos

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

In our component-based development methodology, each developer is responsible for ensuring that the software he or she creates is easy to understand and use, and not especially easy to misuse. One common form of misuse is to invoke a library function or method under circumstances where not all of its preconditions are satisfied, leading to undefined behavior. Contracts having undefined behavior are not necessarily undesirable, and (for many engineering reasons) are often optimal. Most would agree that a well-implemented library should do something other than silently continue when a pre-condition violation is detected, although these same folks might not agree on what specific action should be taken. Unfortunately, validating preconditions implies writing additional code that will execute at runtime. More code runs slower, and some would fairly argue that they should not be forced to pay for redundant runtime checks in the library software they use. Whether and to what extent library functions should validate their preconditions, and what should happen if a precondition violation is detected are questions that are best answered on an application by application basis - i.e., by the owner of main. "Defensive Programming Done Right" makes it all possible.

In this talk, we begin by reviewing the basic concepts of Design-By-Contract (DbC), and what we mean by the term "Defensive Programming" (DP). We then explore our overall approach to institutionalizing defensive programming in robust reusable library software such that each application can conveniently specify both the runtime budget (e.g., none, some, lots) for defensive checking, and also the specific action to be taken (e.g., abort, throw, spin) should a precondition violation occur. Along the way, we touch on how modern compilers and linkers work, binary compatibility, and the consequences of possibly violating the one-definition rule in mixed-mode builds. We conclude the talk by describing and then demonstrating our "negative testing" strategy (and supporting test apparatus) for readily verifying, in our component-level test drivers, that our defensive checks detect and report out-of-contract client use as intended. Actual source for the supporting utility components will be presented throughout the talk and made available afterwards.

CppCon 2014 Defensive Programming Done Right, Part I--John Lakos

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:

Defensive Programming Done Right, Part I

by John Lakos

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

In our component-based development methodology, each developer is responsible for ensuring that the software he or she creates is easy to understand and use, and not especially easy to misuse. One common form of misuse is to invoke a library function or method under circumstances where not all of its preconditions are satisfied, leading to undefined behavior. Contracts having undefined behavior are not necessarily undesirable, and (for many engineering reasons) are often optimal. Most would agree that a well-implemented library should do something other than silently continue when a pre-condition violation is detected, although these same folks might not agree on what specific action should be taken. Unfortunately, validating preconditions implies writing additional code that will execute at runtime. More code runs slower, and some would fairly argue that they should not be forced to pay for redundant runtime checks in the library software they use. Whether and to what extent library functions should validate their preconditions, and what should happen if a precondition violation is detected are questions that are best answered on an application by application basis - i.e., by the owner of main. "Defensive Programming Done Right" makes it all possible.

In this talk, we begin by reviewing the basic concepts of Design-By-Contract (DbC), and what we mean by the term "Defensive Programming" (DP). We then explore our overall approach to institutionalizing defensive programming in robust reusable library software such that each application can conveniently specify both the runtime budget (e.g., none, some, lots) for defensive checking, and also the specific action to be taken (e.g., abort, throw, spin) should a precondition violation occur. Along the way, we touch on how modern compilers and linkers work, binary compatibility, and the consequences of possibly violating the one-definition rule in mixed-mode builds. We conclude the talk by describing and then demonstrating our "negative testing" strategy (and supporting test apparatus) for readily verifying, in our component-level test drivers, that our defensive checks detect and report out-of-contract client use as intended. Actual source for the supporting utility components will be presented throughout the talk and made available afterwards.

CppCon 2014 Lock-free by Example--Tony Van Eerd

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:

Lock-free by Example

by Tony Van Eerd

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

Dive into and follow along making a lock-free queue.

In particular, a multi-producer, multi-consumer, growing, shrinking, mostly contiguous, lock-free circular queue.

With this single (complicated!) example, we will come across, and attempt to solve, many of the typical problems found in lockfree programming, and delve into the pros and cons of various solutions to those problems.

Eggs.Variant - Part II (the constexpr experience)--K-ballo

A link to make type-safe unions:

Eggs.Variant - Part II (the constexpr experience)

by K-ballo

From the article:

Ruminations on the development of Eggs.Variant, a C++11/14 generic, type-safe, discriminated union. Part I explored a straightforward implementation based on untyped raw storage appropriate to hold any of the variant members. It was noted, however, that such an implementation would never be constexpr-aware. It's time to throw it away and start from scratch in order to properly support constexpr...

CppCon 2014 Generic Programming with Concepts Lite, Part II--Andrew Sutton

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:

Generic Programming with Concepts Lite, Part II

by Andrew Sutton

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

In this talk, I will give an overview of the Concepts Lite language extension for C++ and present examples of its use in design and implementation of real-world generic libraries. Concepts Lite provides the ability for programmers to directly state constraints on template arguments as part of the template declaration. These constraints are predicates which determine whether or not a template argument can be used with that template. Constraints are checked by the compiler at the point of use, meaning that that effectively constrained generic libraries will not suffer from the usual problems of insane diagnostics. Libraries written using concepts will be far more readable and maintainable than the status quo. This talk will focus on generic programming, proposed language features, and their use in building real-world libraries.

Concepts Lite is a forthcoming ISO Technical Specification (TS) aimed at publication alongside C++14. Concepts Lite is implemented in a branch of GCC, which will be made available to the audience for experiments and experience.