advanced

Automatic two-phase init -- Krzysztof Ostrowski

Deferred initialisation for classes that inherit constructors, or Automatic two-phase init.

Deferred initialisation for classes that inherit constructors

by Krzysztof Ostrowski

From the article:

Constructor inheritance through using-declaration is a powerful technique that can be easily used to introduce pre-defined behaviour to custom types. As an example, consider a generic visitor design pattern implementation that is parametrised by the names of visitable types, and an unique tag that identifies given visitor template instance. Such an instance can be "mixed-in" into a custom type D by simply deriving from it... and inheriting its constructors to make it behave as it would be a Visitor template instance itself:

struct D
  : Visitor<
        A         // the tag
      , X, Y, Z   // "list" of visitable types
      >
{
    using Visitor::Visitor;
};
What if there is a need to run an "additional" initialisation code as it would be run in the D constructor if one were there? Bjarne Stroustrup suggests member-initializers that do half of a work we would like to do here. While direct member initialisation sets required initial values for all the members (except bit field members), it does not offer a direct way to execute custom code that makes use of those members, the custom code that typically resides in the constructor's body.
This article presents a solution that enables injection of a custom code to be executed once all the non-static members are initialised.

CppCon 2016: Regular Expressions in C++, Present and Future--Tim Shen

Have you registered for CppCon 2017 in September? Don’t delay – Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2016 for you to enjoy. Here is today’s feature:

Regular Expressions in C++, Present and Future

by Tim Shen

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

Regular expressions are widely used in application development and data processing, yet it is challenging to design and implement a regular expression library that is expressive, efficient and safe.

In this talk, Tim Shen, the current maintainer of libstdc++'s <regex>, will introduce the basics of implementing regular expressions in C++, the status of existing implementations, and what is expected from the standardization process.

For the implementation, several data structures and algorithms will be introduced, with pros and cons listed; we will show how several popular implementations (Boost.Regex, Boost.Xpressive, <regex> from standard library implementations, RE2, etc) pick their algorithms. Several popular features/patterns that hurt performance will be explained, with a "safe" regex usage suggested. Finally a wishlist of features will be presented, in order to deliver a more efficient and usable regex library.

Quick Q: How to require an exact function signature in the detection idiom?

Quick A: Use is_detected

Recently on SO:

How to require an exact function signature in the detection idiom?

With C++17 is_detected, you may do

template <typename T, typename Ret, typename Index>
using subscript_t = std::integral_constant<Ret (T::*) (Index), & T::operator[]>;

template <typename T, typename Ret, typename Index>
using has_subscript = is_detected<subscript_t, T, Ret, Index>;

static_assert(has_subscript<std::vector<int>, int&, std::size_t>::value, "!");
static_assert(!has_subscript<std::vector<int>, int&, int>::value, "!");

Zero-allocation continuations in C++17 — Vittorio Romeo

This series of articles show the design and implementation of future-like asynchronous computation chains that do not require any dynamic memory allocation or type erasure. 

by Vittorio Romero

From the article:

I'd like to show an alternative design [for futures] that doesn't require any allocation whatsoever and still enables users to build up asynchronous computation chains using facilities such as `when_all` and `.then`. [...] The idea behind it is to encode the entire computation chain into a single object with a huge type.

Fuzzing beast with libFuzzer

A short blog post about my experience in fuzzing beast during my boost review

Fuzzing beast with libFuzzer

by Jens Weller

From the article:

During the weekend I wanted to take a closer look at beast, a http library proposed for boost. I planned to write an http client class, as thats something I'll need in some project later anyways. I've been looking at beast on and off for a few month now, and started by reviewing the documentation and examples to get a feel for the library it self.

Making things do stuff - Part 6 and 7--Glennan Carnie

The series continues.

Making things do stuff

by Glennan Carnie

Part 6Part 7

From the article:

As code designers we tend to eschew specific ‘stove-pipe’ code in favour of reusable code elements.  Up until now we’ve been coding some very specific examples so it’s probably worth looking at some more generic solutions...

5 years of Meeting C++

Meeting C++ exists now for 5 years, lets celebrate on the blog:

5 years of Meeting C++

by Jens Weller

From the article:

Just a little bit more then 5 years ago, Meeting C++ went public. Since then, it has been a wild ride and huge success. Today, Meeting C++ reaches over 50k in social media, the conference it self has grown from 150 to 600 in its 5 editions...