Enabling forward traversal -- Krzysztof Ostrowski

Krzysztof Ostrowski describes in his article enabling iteration over a sequence of objects of given type without changing the type name itself.

Enabling forward traversal

by Krzysztof Ostrowski

From the article:

Let's consider following example. We have legacy interface that constructs object of type T using information stored in object of type U:

bool build_from(T& into, const U& from);

Such a build_from can be deserialiser function, e.g. from JSON to C++ type, for example:

result_type deserialise(T& into, const json_node_type& from);

Ideally, we should return into rather than taking it as an input argument, i.e. return optional<T> or type that carries information about the errors too, like C++ counterpart of Either. Unfortunately, we have to deal with legacy interafce, so that existing contracts cannot be broken, and our patch sets shall favour composition and extension over the modification.

With deserialise we know how to convert internal JSON representation into object of type T. That works fine for non-structured types. JSON offers associative containers (dictionaries, hashes, structures as defined in YAML) and collections. Dictionaries map easily to product types, struct in C++, and for those we typically need custom deserialisation procedures. Collections may be seen as abstractions over structures, or – more functionally – as sequenced values of type T for collection of type [T]. Since we know how to deserialise objects of type T, we can deserialise [T] by simply mapping deserialise over a sequence of T objects, that is doing forward traversal. Unfortunately we have just one JSON node from, not a sequence of nodes. We need to enable forward traversal for the type json_node_type with minimal number of changes.

Qt 5.7 released--Lars Knoll

The new Qt has arrived!

Qt 5.7 released

by Lars Knoll

From the article:

I’m very happy to announce that Qt 5.7 is now available. It’s been only 3 months since we released Qt 5.6, so one might expect a rather small release with Qt 5.7. But apart from the usual bug fixes and performance improvements, we have managed to add a whole bunch of new things to this release.

Quick Q: Do mutexes guarantee ordering of acquisition?

Quick A: They do not.

Recently on SO:

Do mutexes guarantee ordering of acquisition?

Known problem. C++ mutexes are thin layer on top of OS-provided mutexes, and OS-provided mutexes are often not fair. They do not care for FIFO.

The other side of the same coin is that threads are usually not pre-empted until they run out of their time slice. As a result, thread A in this scenario was likely to continue to be executed, and got the mutex right away because of that.

Overload 133 is now available

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

Overload 132

From the journal:

Dogen: The Package Management Saga
How do you manage packages in C++? Marco Craveiro eventually discovered Conan after some frustrating experiences. by Marco Craveiro

QM Bites – Order Your Includes (Twice Over)
Header includes can be a shambles. Matthew Wilson encourages us to bring some order to the chaos. by Matthew Wilson

A Lifetime In Python
Resource management is important in any language. Steve Love demonstrates how to use context managers in Python. by Steve Love

Deterministic Components for Distributed Systems
Non-deterministic data leads to unstable tests. Sergey Ignatchenko considers when this happens and how to avoid it. by Sergey Ignatchenko

Programming Your Own Language in C++
Scripting languages allow dynamic features easily. Vassili Kaplan writes his own in C++ allowing keywords in any human language. by Vassili Kaplan

Concepts Lite in Practice
Concepts should make templates easier to use and write. Roger Orr gives a practical example to show this. by Roger Orr

Afterwood
Magazines sometimes use the back page for adverts or summaries. Chris Oldwood has decided to provide us with his afterwords, or ‘afterwood’. by Chris Oldwood

CppCon 2015 Haskell Design Patterns for Genericity & Asynchronous Behavior--Sherri Shulman

Have you registered for CppCon 2016 in September? Don’t delay – Early Bird registration is open now.

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

Haskell Design Patterns for Genericity & Asynchronous Behavior

by Sherri Shulman

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

The paper explores some of Haskell's support for genericity through type classes, Functors, Monads, and Continuations and their impact on lanugages such as C++, Scala, and Rust. We explore these language features and consider alternatives that have been proposed to existing language features, including Object Algebras, GADTs, Open data types, open pattern matching, and extensions to Haskell's type system that impact the type inference algorithm and decidability. We use a number of case studies to demonstrate what proposed solutions look like in the target languages, considering how easy they are to use and how well the solutions integrate with existing linguistic features.

Building And Packaging C++ Modules In Vs2015--Conan's blog

Modules in Conan explained:

Building And Packaging C++ Modules In Vs2015

by Conan's blog

From the article:

This post makes a brief introduction to the C++ modules (we wished C++17, but we will have to wait). Modules have already been experimentally available in an early implementation in CLang, and now Microsoft is also providing them in Visual Studio 2015. We will see their syntax and how to build them, as introduced in the Visual Studio Blog, and at the same time, we will show how to create and consumes packages with C++ modules with conan C/C++ package manager.

Implementing Queues for Event-Driven Programs--“No Bugs” Hare

An interesting article:

Implementing Queues for Event-Driven Programs

by “No Bugs” Hare

From the article:

We’ve already discussed things related to sockets; now let’s discuss the stuff which is often needed (in particular, it is of Utmost Importance when implementing Reactors), but which is not that common to be universally available as a part of operating system.

I’m speaking about queues. And not only just about “some” queue, but about queues which have certain properties desirable for our Reactors a.k.a. ad-hoc Finite State Machines a.k.a. Event-Driven Programs.

GoingNative 50: New Visual C++ Code Optimizer--Eric Battalio, Steve Carroll and Augustin Popa

The new GoingNative is out!

GoingNative 50: New Visual C++ Code Optimizer

by Eric Battalio, Steve Carroll and Augustin Popa

From the video:

Happy 50th episode! This episode covers our new, more advanced code optimizer for the Visual C++ compiler back-end. It provides many improvements for both code size and performance, bringing the optimizer to a new standard of quality expected from a modern native compiler.

This is the first public release and we are encouraging people to try it and provide suggestions and feedback about potential bugs. The official release of the new optimizer is expected to be Visual Studio Update 3, while the release available today is unsupported and mostly for testing purposes.

Read our blog post to get the details!