Articles & Books

It had to be done - Abusing co_await for optionals--redditsoaddicting

The future is not here yet that it's already full of resources!

It had to be done - Abusing co_await for optionals

by redditsoaddicting

From the article:

I finally got around to playing with coroutines in the context of non-future types. I always guessed this could be done. For optionals specifically, the idea is that you do auto x = co_await foo(); and either x is the value in the optional or the function immediately returns an empty optional...

C++17 in details: Attributes

Another part of the series on C++17 details.

C++17 in details: Attributes

by Bartlomiej Filipek

From the article:

Previously each compiler could specify its own syntax and list of available attributes, but in modern C++ the committee tried to standardize this: there are some extracted, common parts. Plus each compiler is not blocked to add its own extensions. Maybe at some point, we’ll move away from __attribute or __declspec or #pragma?

Quick Q: How to make my custom type to work with “range-based for loops”?

Quick A: Create member functions begin() and end() returning an iterator.

Recently on SO:

How to make my custom type to work with “range-based for loops”?

The standard has been changed since the question (and most answers) were posted in the resolution of this defect report.

The way to make a for(:) loop work on your type X is now one of two ways:

  • Create member X::begin() and X::end() that return something that acts like an iterator
  • Create a free function begin(X&) and end(X&) that return something that acts like an iterator, in the same namespace as your type X.

And similar for const variations. This will work both on compilers that implement the defect report changes, and compilers that do not.

Quick Q: Initializing a C++11 string with {}

Quick A: It calls the initializer_list constructor that has the same effect in this case.

Recnetly on SO:

Initializing a C++11 string with {}

The {} initialization syntax is known as the uniform initialization syntax, it has a few key differences, but in your code as is they both do the same thing - construct a std::string object from the string literal "Test"

Initializing an object with an assignment is essentially the same as putting the right hand side in parentheses and constructing the object. For example the below two are the same

T obj = a;
T obj(a);

So you should be asking yourself, what is the difference between constructing a string object the following two ways

std::string{"Test"};
std::string("Test");

And the answer is that both the constructions above are the same and call the same constructor for std::string

For more on uniform initialization see https://softwareengineering.stackexchange.com/questions/133688/is-c11-uniform-initialization-a-replacement-for-the-old-style-syntax

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...

Functors in C++-Part I and II--Mayank Jain

And how they are used by the std:

Functors in C++

by Mayank Jain

Part I - Part II

From the article:

Functor or function object is a C++ class which defines the operator ( ). Functor let’s you create objects which “looks like” functions...

Metaclasses for embedded domain specific languages -- Simon Brand

A post about an application of the new Metaclasses proposal.

Metaclasses for embedded domain specific languages

by Simon Brand

From the article:

Metaclasses are a proposed feature to C++ which will allow the creation of abstractions over classes and the extension of the language’s type definition system. Templates are a powerful host for other languages, and metaclasses only make them more so.

Modern C++ CI--Juan Medina

Complete set up of a project:

Modern C++ CI

by Juan Medina

From the article:

Modern C++ is great, some people are even calling it a new language, but is not only the language what is evolving the tool-chain is getter better, so doing continuous integration for cross platform projects is simple and effective.

I decide to do a simple project using some of the C++14 features and following the C++ Core Guidelines whenever its possible. The result is available in this repository.

A more realistic coroutine--Kirit Sælensminde

What’s the point of coroutines?

A more realistic coroutine

by Kirit Sælensminde

From the article:

Having gotten something working, we still have a small problem. We have a coroutine that we can start, and we can choose when to suspend it, but we can't yet resume it.

The coroutines TS describes a class std::experimental::coroutine_handle which is our interface to the coroutine itself. It's a template which is supposed to be told the promise_type we're using...