Articles & Books

Fun with folds--Nick Athanasiou

Everything is in the title:

Fun with folds

by Nick Athanasiou

From the article:

A fold is a higher order function (a function that has one or more function parameters and/or returns a function) that is recursively applied over a data structure...

Overload 130 is now available

ACCU’s Overload journal of December 2015 is out. It contains the following C++ related articles.

Overload 130 / PDF

From the journal

Type Mosaicing with Consultables and Delegates

If several classes need to work together lots of boilerplate code is often needed. Nicolas Bouillot introduces type mosaicing to avoid this.

The Universality and Expressiveness of std::accumulate

Folding is a highly generic operation available through std::accumulate. Paul Keir goes beyond reduction, with the help of C++14’s polymorphic lambdas.
QM Bites – The two sides of Boolean Parameters
Boolean parameters are tempting but make life difficult. Matthew Wilson advises us to avoid them (almost) all the time.
Identify your Errors better with char[]
Error codes still get used instead of exceptions. Patrick Martin and Dietmar Kühl consider how to use char arrays for better information.
CPU Clocks and Clock Interrupts, and Their Effects on Schedulers
Instructions to sleep for a second almost never result in precisely one second’s sleep. Bob Schmidt walks us through the mechanics of why.
 

All Meeting C++ Lightning Talk videos are online

Meeting C++ just started a week ago, and I already managed to edit and upload all lightning talks:

Meeting C++ 2015 - all lightning talks are now online at youtube

by Jens Weller

From the article:

This year for the very first time we had lightning talks at the Meeting C++ conference. Two sessions with each 5 lightning talks were held...

Modern Asynchronous Request/Reply with DDS-RPC -- Sumant Tambe

rtidds.PNGThis article is considers lots of approaches to solving a concurrency problem, but of particular interest are the sections showing the power of the Concurrency TS future.then extension and the coroutines proposal:

Modern Asynchronous Request/Reply with DDS-RPC

by Sumant Tambe

From the article:

A quick look into N4402 reveals that the await feature relies on composable futures, especially .then (serial composition) combinator. The compiler does all the magic of transforming the asynchronous code to a state machine that manages suspension and resumption automatically. It is a great example of how compiler and libraries can work together producing a beautiful symphony.

... Indeed, this is truly an exciting time to be a C++ programmer.

C++ Static Analysis using Clang -- Ehsan Akhgari

How to write/use C++ static analyzer using Clang.

C++ Static Analysis using Clang

by Ehsan Akhgari

From the article:

Large code bases typically develop rules around how various code constructs should be used.  These rules help eliminate bugs resulting from common mistakes.  C++ gives programmers a good amount of power over enforcing such rules using the facilities that the language provides.  As a simple example, if you have a class that should not be inherited from, you can mark the class as final.

Typically one finds themselves in a situation where the language doesn’t provide an easy way to enforcey something.  In that case, the solution is typically enforcing the rules through documentation, code review, etc.  Besides the obvious downside of people making mistakes when checking for these rules, detecting violations of the some rules may be completely impractical.

Quick Q: C++ regex: Conditional replace

Quick A: Use regex_token_iterator

Recently on SO:

C++ regex: Conditional replace

Use regex_token_iterator


#include <regex>
#include <string>
#include <sstream>
#include <set>
#include <map>

std::string replacer(std::string text) {
    std::string output_text;
    std::set<std::string> keywords = { "foo", "bar" };
    std::map<std::string, int> ids = {};

    int counter = 0;
    auto callback = [&](std::string const& m){
        std::istringstream iss(m);
        std::string n;
        if (iss >> n)
        {
            if (keywords.find(m) != keywords.end()) {
                output_text += m + " ";
            }
            else {
                if (ids.find(m) != ids.end()) {
                    output_text += "ID" + std::to_string(ids[m]) + " ";
                }
                else {
                    // not found
                    ids[m] = counter;
                    output_text += "ID" + std::to_string(counter++) + " ";
                }
            }
        }
        else
        {
            output_text += m;
        }
    };

    std::regex re("\\b\\w*\\b");
    std::sregex_token_iterator
        begin(text.begin(), text.end(), re, { -1, 0 }),
        end;
    std::for_each(begin, end, callback);
    return output_text;
}

 

Getting Started with Modules in C++--Kenny Kerr

The basics of creating and using a module:

Getting Started with Modules in C++

by Kenny Kerr

From the article:

Visual Studio 2015 Update 1 shipped with experimental support for a module system for C++. You can learn about it from this talk given by Gabriel Dos Reis at CppCon. Creating and consuming modules is very simple, but getting started with the compiler is not that obvious. At least it wasn’t very obvious to me, so here’s a quick introduction to get you started.

C++ Modules in VS 2015 Update 1--Gabriel Dos Reis and Andrew Pardoe

Modules in Visual:

C++ Modules in VS 2015 Update 1

by Gabriel Dos Reis and Andrew Pardoe

From the article:

The VC++ team is excited to preview a new feature in VS 2015 Update 1: The first experimental implementation of A Module System for C++, proposed for C++17. That proposal was approved by the C++ standards Evolution Working Group for a C++17 Technical Specification at the Fall 2015 meeting in Kona, Hawai’i. The draft wording for the Technical Specification is under review by the C++ Standards Core Working Group.

 

The most dangerous function in the C/C++ world

Most errors that I see in the projects are related to the usage of this particular memset() function.

The most dangerous function in the C/C++ world

by Andrey Karpov

From the article:

Now I have another interesting observation. Using one or another function, the programmers can make mistakes. That is clear, you may say. But the probability of the error may also depend on the function. In other words, some functions provoke errors, and some don't. And now I am ready to name the function which causes most of the troubles and using which you have the biggest chance of an epic fail.