C++ User Group Meetings in June

Again, the monthly overview on the C++ User Group Meetings

C++ User Group Meetings in June

by Jens Weller

The complete list:

  • 11.6 C++ UG San Francisco/Bayarea - "Good enough" is good enough! by Alex Martelli
  • 12.6 C++ UG Dresden - Uniforme Initialisierung
  • 12.6 C++ UG Dutch/Amsterdam - Concurrency in C++11
  • 17.6 C++ UG Berlin - Template Metaprogramming for numerical problems
  • 18.6 C++ UG NRW/Düsseldorf - Drawing with Cairo
  • 18.6 C++ UG Northwest/Seattle - High Reliability Systems
  • 21.6 C++ UG Russia/St. Petersburg
  • 25.6 C++ UG Hamburg - Code Dojo
  • 26.6 C++ UG Munich - boost.asynchronous
  • 28.6 C++ UG Italy/Milano

Videos from C++ track on NDC Oslo

ndc-2014.pngThere was a very strong C++ track on NDC Oslo this year. Here is an overview of the videos recorded for the C++ track:

Day 1, June 4, 2014

  • C++14, Nico Josuttis (video)
  • Effective Modern C++, Scott Meyers (video)
  • Error Handling in C++, Andrei Alexandrescu (video)
  • Move, noexcept, and push_back(), Nico Josuttis (video)
  • C++ Type Deduction and Why You Care, Scott Meyers (video)
  • Generic and Generative Programming in C++, Andrei Alexandrescu (video)

Day 2, June 5, 2014

  • C++ -- where are we headed?, Hubert Matthews (video)
  • Three Cool Things about D, Andrei Alexandrescu (video)
  • The C++ memory model, Mike Long (video, slides)
  • C++ for small devices -- Isak Styf (video)
  • Brief tour of Clang, Ismail Pazarbasi (video)
  • Insecure coding in C and C++, Olve Maudal (video, slides)
  • So you think you can int? (C++), Anders Knatten (video)

Enjoy!

NDC Oslo is an annual conference for programmers (~1600 delegates). 2 days of preconference courses/workshops, and then 9 tracks of technology talks for 3 days. The dates for 2015 are June 15-19. There will be a strong C++ track next year as well. Save the dates and stay tuned.

Generator functions in C++—Paolo Severini

Paolo Severini expands the concept of resumable functions to support generator functions, providing the ability of lazily producing the values in a sequence only when they are needed.

Generator functions in C++

by Paolo Severini

From the article:

In the previous post we had a look at the proposal of introducing resumable functions into the C++ standard to support writing asynchronous code modeled on the C# async/await pattern.

We saw that it is already possible to experiment with the future resumable and await keywords in Visual Studio, by installing the latest November 2013 CTP. But the concept of resumable functions is not limited to asynchrony; in this post we’ll see how it can be expanded to support generator functions.

Generator functions and lazy evaluation

In several languages, like C# and Python, generator functions provide the ability of lazily producing the values in a sequence only when they are needed. ...

Masking a Class in Boost.Graph—Vadim Androsov

Here's an experience report about using Boost's graph support in an existing game app, with some notes about Boost Concepts:

Masking a Class in Boost Graph. Part 1: Let the Interface Be

Masking a Class in Boost Graph. Part 2: Completing the Implementation of Concept Support

by Vadim Androsov

From the articles:

I had to rebuild a pathfinding algorithm for our game recently. The previous one (Boost Concepts) was bad as any sidestep was dangerous. So I wanted to take a ready algorithm from a good source. That’s exactly when I remembered about boost as there’s functionality for working with graphs. Unfortunately “find a function, call it and everything will work” approach wasn’t meant to be realized. The library is focused on the maximum use flexibility which has badly affected its simplicity. But it’s better than creating it from scratch (then fixing it). I didn’t want to bother with other libraries, while boost has already been used in the project. ...

N4056: Minimal incomplete type support for standard containers—Zhihao Yuan

A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N4056

Date: 2014-05-23

Minimal incomplete type support for standard containers

by Zhihao Yuan

Excerpt:

In the previous version (N3890) of this paper, we explored the possibility to make all STL containers usable in the recursive data structure definitions, such as

struct Entry
{
    std::list<Entry> messages;
    // ...
};

Based on the discussion on the Issaquah meeting, we achieved the consensus to processed with the approach – “Containers of Incomplete Types”, but limit the scope to std::vector, std::list, and std::forward_list, as the first step.

Are lists evil?—Bjarne Stroustrup

Recently added to Bjarne Stroustrup's FAQ:

Are lists evil?

by Bjarne Stroustrup

From the FAQ:

According to some corners of the Web, I am under the impression that vectors are always better than linked lists and that I don't know about other data structures, such as trees (e.g. std::set) and hash tables (e.g., std::unordered_map). Obviously, that's absurd.

The problem seems to be an interesting little exercise that John Bentley once proposed to me: Insert a sequence of random integers into a sorted sequence, then remove those elements one by one as determined by a random sequece of positions: Do you use a vector (a contiguously allocated sequence of elements) or a linked list? For example, see Software Development for Infrastructure. I use this example to illustrate some points, encourage thought about algorithms, data structures, and machine architecture, concluding:

  • don't store data unnecessarily,
  • keep data compact, and
  • access memory in a predictable manner.

Note the absence of "list" and "vector" in the conclusion. Please don't confuse an example with what the example is meant to illustrate.

I used that example in several talks, notably:

This video has been popular: It has been downloaded more than 250K times (plus another 50K+ times at verious other sites). My impression is that many viewers failed to understand that the purpose of that example is to illustrate some general principles and to make people think. Initially, most people say ``List of course!'' (I have tried asking that question many times) because of the many insertions and deletions ``in the middle'' (lists are good at that). That answer is completely and dramatically wrong, so it is good to know why.

I have been using the example for years, and had graduate students implement and measure dozens of variants of this exercise and different exercises. Examples and measurements by others can be found on the Web. Of course,

  • I have tried maps (they are much better than lists, but still slower than vectors)
  • I have tried much larger elements sizes (eventually lists come into their own)
  • I have used binary search and direct insertion for vectors (yes, they speed up even further)
  • I checked my theory (no I'm not violating any big-O complexity rule; it is just that some operations can be dramatically more expensive for one data structure compared to another)
  • I have preallocated links (that's better than std::list but the traversal still kills performance)
  • I have used singly-linked lists, forward_lists, (that doesn't make much difference, but makes it a bit harder to ensure that the user code is 100% equivalent)
  • I know (and say) that 500K lists are not common (but that doesn't matter for my main point). We use many structures (large and small) where there is a choice between linked and contiguous reprentation.
  • I know that for insertion push_front() is faster for std::lists and push_back()s is faster for vectors. You can construct examples to illustrate that, but this example is not one of those.

My point is not about lists as such. They have their uses, but this example isn't one of them. Please don't confuse the example with what the example is used to illustrate. This example is about use of memory: We very often create a data structure, do some computation on it requiring access (often, traversal), and then delete it. The ordered sequence is simply an example of such use and the example is presented to get people to think about what matters in such cases. My suggestion is:

  • don't store data unnecessarily,
  • keep data compact, and
  • access memory in a predictable manner.

I emphasize the importance of cache effects. In my experience, all but true experts tend to forget those when algorithms are discussed.

And, yes, my recomendation is to use std::vector by default. More generally, use a contiguous representation unless there is a good reason not to. Like C, C++ is designed to do that by default.

Also, please don't make statements about performance without measurements. I have seen a case where changing a zero-to-two-element list to a zero-to-two-element vector made a factor-of-two difference to an algorithm. I didn't expect that. Nor did other experts looking at the code.

N3995: A proposal to add shared_mutex (untimed) (Revision 2)—Gor Nishanov

A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N3995

Date: 2014-05-20

A proposal to add shared_mutex (untimed) (Revision 2)

by Gor Nishanov

Excerpt:

This revision is a minor edit of an earlier paper N3961 that clarifies that proposed modifications to the standard be incorporated into the Concurrency Technical Specification N3993.

CppCon Program Preview, 3 of N—Boris Kolpackov

cppcon-093.PNG

More CppCon 2014 accepted talks have just been announced, below. For past announcements about the conference program, see also:

Super Early Bird registration has sold out, but Early Bird registration is available until June 30.

 

CppCon Program Preview, 3 of N

by Boris Kolpackov

From the announcement:

Herb Sutter: “Standardization Update: C++14 and the Seven Dwarfs”
Stephan T. Lavavej: “STL Features And Implementation Techniques”
Jared Hoberock: “Parallelizing the Standard Algorithms Library”
Howard Hinnant: “Types Don’t Know #”
Lisa Lippincott: “How to call C libraries from C++”

 

Herb Sutter: “Standardization Update: C++14 and the Seven Dwarfs"

Standardization has accelerated: By the time we meet at CppCon, C++14 might already be ratified. But that’s only one of eight (so far) work items now in flight. In this session, the chair of the ISO C++ committee will give a brief summary of the new features coming in C++14 itself, and then a tour of the seven (7) near-term separate Technical Specifications already underway — think of these as the “C++14 wave” of deliverables. The ISO C++ committee has transitioned to a “decoupled” model where updated versions of the standard are published more frequently, while at the same time major pieces of work can progress and be published independently from the Standard itself and delivered asynchronously in the form of Technical Specifications (TS’s) that are separate from the main Standard and can later be incorporated into the Standard. Come to this session to see how this is helping both the standard and C++ compiler implementations near you stay current with the latest in C++.

Speaker’s bio: Herb Sutter is the author of several best-selling books about C++, chair of the ISO C++ standards committee, and a software architect at Microsoft.

 

Stephan T. Lavavej: “STL Features And Implementation Techniques"

This session will cover selected STL features from C++11/14, both explaining how to use them and delving into implementation techniques that could be useful outside the STL. I will avoid covering popular features you’re already using (e.g. make_shared, make_unique) and obscure features of limited use (e.g. forward_list). The focus will be on useful but underappreciated features like dual-range algorithms, minimal allocators, and heterogeneous associative lookup.

Speaker’s bio: Stephan T. Lavavej is a Senior Developer at Microsoft. Since 2007, he’s worked with Dinkumware to maintain Visual C++’s implementation of the C++ Standard Library. He also designed a couple of C++14 features: make_unique and the transparent operator functors. He likes his initials (which people can actually spell) and cats (although he doesn’t own any).

 

Jared Hoberock: “Parallelizing the Standard Algorithms Library"

Until recently, C++ programmers building parallel programs found little support for parallelism in the standard toolbox. That’s changing with the technical specification on Extensions for Parallelism in C++. This talk will explore how programmers can build portable parallel programs from high-level parallel algorithms which can execute on CPU threads, vector units, and even GPUs.

Speaker’s bio: Jared Hoberock is a research scientist at NVIDIA where he develops the Thrust parallel algorithms library and edits the Technical Specification on Extensions for Parallelism for C++.

 

Howard Hinnant: “Types Don’t Know #“

This presentation will be based on the C++ standards committee proposal of a new hashing infrastructure that completely decouples hashing algorithms from individual types that need to be hashed. This decoupling divides the hashing computation among 3 different programmers who need not coordinate with each other:

  1. Authors of hashable types (keys of type K) write their hashing support just once, using no specific hashing algorithm. This code resembles (and is approximately the same amount of work as) operator== and swap for a type.
  2. Authors of hashing algorithms write a functor (e.g. H) that operates on a contiguous chunk of generic memory, represented by a void const* and a number of bytes. This code has no concept of a specific key type, only of bytes to be hashed.
  3. Clients who want to hash keys of type K using hashing algorithm H will form a functor of type std::uhash<H> to give to an unordered container: unordered_set<K, uhash<H>>

Speaker’s bio: Howard Hinnant is a lead author of several C++11 features including: move semantics, unique_ptr, <mutex>, <condition_variable> and <chrono>. Coming in C++14: <shared_mutex>. Howard is also a lead author on two open source projects: a std::lib implementation and an Itanium ABI implementation.

 

Lisa Lippincott: “How to call C libraries from C++“

Many libraries used by C++ programs present C-like interfaces that are compatible with C++, but are not directly compatible with good C++ style. Using these libraries directly is error-prone in many of the ways C++ is designed to avoid. It is better to pass through an interface layer that presents good C++ style on the C++ side. But writing such an interface layer is daunting. Completing it may be an enormous task, as are documenting it and maintaining it as the underlying library evolves. To address this problem, I will present a style of writing such interfaces that can be used incrementally as needed, and that reduces documentation cost. I will also present a small library that supports the writing of interface layers in this style.

Speaker’s bio: Lisa Lippincott is a Chief Software Architect at Tanium, a bay-area startup. Her claim to fame is writing one phrase appearing in the C++ standard. In her spare time, she studies mathematical logic with a category-theoretic approach.

Lightweight HTTP Server in less than 40 Lines on libevent and C++11—NYM

kukuruku.PNGFresh on Kukuruku:

Lightweight HTTP Server in less than 40 Lines on libevent and C++11

by NYM

From the article:

Looking through programming articles sometimes I see posts about creating your own HTTP server. I am most interested in C++ so I often read blogs about it. After looking them through you could easily write you own web server “on sockets” using boost.asio or something else. I also examined libevent and libev. Each of them has its advantages. Libevent is of great interest to me for developing a small HTTP server. Considering some innovations in C++11 the code becomes much more space-efficient and allows for the creation of a basic HTTP server in less than 40 lines.