Articles & Books

Why you should use Boost.MultiIndex (Part I)--David Gross

Did you know that container?

Why you should use Boost.MultiIndex (Part I)

by David Gross

From the article:

Although Boost.MultiIndex is a pretty old library — introduced in Boost 1.32, released in 2004 — I found it rather unsung and underestimated across the C++ community in comparison to other non-standard containers.

In this article, split into multiple parts, I will highlight all the benefits you can get using boost::multi_index_container instead of the standard containers: faster, cleaner and simpler code.

Collaborative Online Compilers

I was doing some research on possible live formats...

Collaborative Online Compilers

by Jens Weller

From the article:

While doing some brainstorming for possible (youtube) live formats with C++ content, the thought of having a shared online IDE/Compiler came into my mind. Think of Google Docs but for C++...

checking expression validity in-place with C++17--Vittorio Romeo

An introduction to the world of C++17.

checking expression validity in-place with C++17

by Vittorio Romeo

From the article:

When writing generic code, it is sometimes useful to check whether or not a particular SFINAE-friendly expression is valid (e.g. to branch at compile-time). Let's assume that we have the following class declarations...

struct Cat
{
    void meow() const { cout << "meow\n"; }
};

struct Dog
{
    void bark() const { cout << "bark\n"; }
};

...and that we would like to write a template function make_noise(x) that calls x.meow() and/or  x.bark() if they are well-formed expressions:

template <typename T>
void make_noise(const T& x)
{
    // Pseudocode:
    /*
        if(`x.meow()` is well-formed)
        {
            execute `x.meow();`
        }
        else if(`x.bark()` is well-formed)
        {
            execute `x.bark();`
        }
        else
        {
            compile-time error
        }
    */
}

In this article I'll show how to implement the pseudocode in:

C++11: using std::void_t and std::enable_if.

C++14: using boost::hana::is_valid and vrm::core::static_if.

C++17: using if constexpr(...), constexpr lambdas, and std::is_callable. This version will allow expression validity to be checked in-place (i.e. directly in the if constexpr predicate). Variadic preprocessor macros will also be used to make the user code easier to read and maintain...

Getting your head around auto’s type-deduction rules--Glennan Carnie

Are the rules clear to you?

Getting your head around auto’s type-deduction rules

by Glennan Carnie

From the article:

Automatic type-deduction is perhaps one of the more divisive features of Modern C++.  At its core it’s a straightforward concept:  let the compiler deduce the type of an object from its initialiser.   Used in the right way this can improve the readability and maintainability of your code.

However, because auto is based on template type-deduction rules there are some subtleties that can catch the unwary programmer.

In this article we’ll have a look at auto in the context of the template type-deduction rules to see where all these subtleties come from...

Polymorphism Polymorphism -- Adi Shavit

C++17 gives us std::variant<> which allows for a new form of runtime polymorphism.

Polymorphism Polymorphism

by Adi Shavit

From the article:

Polymorphism allows manipulating different types identically when they implement the same interface.
C++ supports both static and dynamic polymorphism.
Dynamic run-time polymorphism in C++ is achieved using sub-typing with inheritance and virtual functions. This is the way it has always been in C++: Polymorphism ⇒ Heap-allocated objects. 

C++17 gives us std::variant<> which allows for a new form of runtime polymorphism.

Coroutines Internals--Marco Alesiani

What are coroutines and why should you care?

Coroutines Internals

    by Marco Alesiani

From the article:

Coroutines provide a powerful abstraction to offer the same level of concurrency one would get with asynchronous callbacks by offering at the same time a chance to write more maintainable code..

Quick Q: Is there a case where ellipsis(vararg) should be preffered over variadic templates?

Quick A: There are several special cases where you may want that, but in general no.

Recently on SO:

Is there a case where ellipsis(vararg) should be preffered over variadic templates?

  1. If you provide a C API with C++ implementation, then templates are not an option for the API. Varargs are.
  2. If you need to support a compiler that doesn't support C++11 or newer standard, then variadic templates are not available. Varargs are.
  3. If you need a compilation firewall. I.e. you need to hide the implementation of the function from the header, then variadic template is not an option. Varargs are.
  4. On memory constrained systems (embedded), the different functions generated by the template may introduce too much bloat. That said, such systems are typically also real time, in which case varargs might also unacceptable due to branching and stack usage.

38 C++ User Group Meetings in November

The monthly overview on upcoming C++ User Group meetings

C++ User Group meetings in November 2016

by Jens Weller

From the article:

This month features 38 C++ User Group meetings already! Plus several C++ Conferences, including Meeting C++ 2016! I included since this month also the LLVM groups which are meeting, there are a few. This is why this month has also 12 new User Groups, with the latest additions of a new group in London and Melbourne!

There are 12 new C++ User Groups: Kitchener, OT, Brussels, Cluj (Qt), Berlin (llvm), St. Petersburg (llvm), Paris (llvm), Bay area (llvm), Cambridge (llvm), Denver, Minsk, London and Melbourne.