A function to visit nodes of a graph with C++14—Adrien Hamelin

Some thoughts about how to visit nodes of a graph:

A function to visit nodes of a graph with C++14

by Adrien Hamelin

From the article:

Visiting a graph is something useful. [...] A classical way to do that is to implement the visitor pattern. [...] it requires to create a Visitor class and to modify each of the possibly visited class to add a virtual accept function. [...] It works well, but surely we can do better...

A gotcha with ptr_vector—Andrzej KrzemieĊ„ski

Do you know Boost.Pointer Container? Andrzej gives some useful information in his recent blog entry:

A gotcha with ptr_vector

He gives answers to these questions:

What would you use boost::ptr_vector for? Why would you need to have a vector of pointers, which you want to delete yourself? Is it because:

  1. You want the objects to remain at the same address even if you re-allocate the array under the vector?
  2. You want to inter-operate with a library that already deals with owing pointers?
  3. You want it to be faster than if you were storing values in std::vector?
  4. You want the “polymorphic behavior” of your objects?

New Security Feature in Visual Studio 2015

An article about a security feature in Visual Studio 2015, called Control Flow Guard.

Visual Studio 2015 Preview: Work-in-Progress Security Feature

by Jim Hogg

From the article:

By simply adding a new option to your Project, the Visual C++ compiler will inject extra security checks into your binaries. These will detect attempts to hijack your code. The check will stop execution of your code, before the hijacker can do damage to your data or PC...

OpenMP* Support in Clang/LLVM: Status Update and Future Directions—Alexey Bataev & Zinovy Nis

A status update for the work done on OpenMP for Clang/LLVM and future directions presented at the 2014 LLVM Developers' Meeting. The slides are also available here.

OpenMP* Support in Clang/LLVM: Status Update and Future Directions

OpenMP is a well-known and widely used API for shared-memory parallelism. Support for OpenMP in Clang/LLVM compiler is currently under development. In this talk, we will present current status of OpenMP support, what is done and what remains to be done, technical details behind OpenMP implementation. Also, we will elaborate on accelerators and pragma-assisted SIMD vectorization, introduced in the latest 4.0 edition of the OpenMP standard.


Quick Q: How do I allow iteration on an internal vector without exposing the vector?—StackExchange

Quick A: By exposing wrapped iterators in your interface.

From Programmers StackExchange, StackOverflow's sister site:

Allow iteration of an internal vector without leaking the implementation

I have a class that represents a list of people.

class AddressBook

  std::vector<People> people;
I want to allow clients to iterate over the vector of people. The first thought I had was simply:
std::vector<People> & getPeople { return people; }
However, I do not want to leak the implementation details to the client. I may want to maintain certain invariants when the vector is modified, and I lose control over these invariants when I leak the implementation.
What's the best way to allow iteration without leaking the internals?

Top 5 Beautiful C++ STD Algorithms Examples—Bartlomiej Filipek

Bartlomiej Filipek shares with us five algorithms using the C++ STD:

Top 5 Beautiful C++ STD Algorithms Examples

by Bartlomiej Filipek

From the article:

Some time ago I've seen an inspiring talk from CppCon 2013: "C++ Seasoning" by Sean Parent. One of the main points of this presentation was not to use raw loops. Instead, prefer to use existing algorithms or write functions that 'wraps' such loops. I was curious about this idea and searched for nice code examples. Here is my short list of usage of algorithms from the C++ std library that might help in writing better code.

Of course. I could not skip two prominent examples from the original "C++ Seasoning" talk: slide and gather...

Overload 124 is now available

overload-124.PNGOverload 124 is now available. It contains the following C++-related articles, and more:


Overload 124

Designing Observers in C++11

The observer pattern is over two decades old. Alan Griffiths fits a venerable design pattern into a contemporary context.

Order Notation in Practice

What does complexity measurement mean? Roger Orr reminds us of the academic definition and looks at some real life situations... std::sort is faster than qsort which can come as a surprise to those who assume C is always faster than C++.

Quick Q: Are std::threads run in the order they’re created?—StackOverflow

Quick A: There is no guarantee that threads will run in a given order.

Recently on SO:

Why don't these threads run in order?

When I run this code:

#include <iostream>
#include <thread>
#include <mutex>

std::mutex m;

int main()
    std::vector<std::thread> workers;
    for (int i = 0; i < 10; ++i)
            std::lock_guard<std::mutex> lock(m);
            std::cout << "Hi from thread " << i << std::endl;

    std::for_each(workers.begin(), workers.end(), [] (std::thread& t)
    { t.join(); });

I get the output:

Hi from thread 7
Hi from thread 1
Hi from thread 4
Hi from thread 6
Hi from thread 0
Hi from thread 5
Hi from thread 2
Hi from thread 3
Hi from thread 9
Hi from thread 8

Even though I used a mutex to keep only one thread access at a time. Why isn't the output in order?

C++ STL for Embedded Developers—John Hinke

E.S.R. Labs presents its STL library adapted to embedded environments and discusses some of the choices they made for it:

C++ STL for Embedded Developers

by John Hinke

From the article:

C++ embedded programming is very difficult. There are some limitations that are not always present in traditional programming environments such as limited memory, slower processors, and older C++ compilers.

We have developed a set of best-practice processes and frameworks to support writing high-quality embedded applications...

Details About Some of the New C++ Language Features—Kangyuan Niu

A few days ago from the Visual Studio C++ blog:

Details About Some of the New C++ Language Features

by Kangyuan Niu

The article explains some new features to come in Visual Studio and, maybe more importantly, why they will come, their purpose. It talks about:

-- Terse Range-Based For Loops

-- Generalized Lambda Capture

-- Dining Philosophers