New Book “C++ Standard Library Quick Reference” Now Available

Marc Gregoire’s and Peter Van Weert’s brand new book “C++ Standard Library Quick Reference”, published by Apress is now available:

C++ Standard Library Quick Reference (Apress) 
C++ Standard Library Quick Reference (Amazon)

By Marc Gregoire and Peter Can Weert

From the abstract:

This quick reference is a condensed reference guide to the essential data structures, algorithms, and functions provided by the C++ Standard Library. Used by millions of C++ programmers on a daily basis, the C++ Standard Library features core classes for strings, I/O streams, and various generic containers, as well as a comprehensive set of algorithms to manipulate them. In recent years, the C++11 and C++14 standards have added even more efficient container classes, a new powerful regular expression library, and a portable multithreading library featuring threads, mutexes, condition variables, and atomic variables.

Needless to say, it is hard to know and remember all the possibilities, details, and intricacies of this vast and growing library. This handy reference guide is therefore indispensable to any C++ programmer. It offers a condensed, well-structured summary of all essential aspects of the C++ Standard Library. No page-long, repetitive examples or obscure, rarely used features. Instead, everything you need to know and watch out for in practice is outlined in a compact, to-the-point style, interspersed with practical tips and well-chosen, clarifying examples. The book does not explain the C++ language or syntax, but is accessible to anyone with basic C++ knowledge or programming experience. Even the most experienced C++ programmer though will learn a thing or two from it and find it a useful memory-aid. Among the topics covered are:

  • The essentials that the C++ Standard Library has to offer
  • How to use containers to efficiently store and retrieve your data
  • How to use algorithms to inspect and manipulate your data
  • How lambda expressions allow for elegant use of algorithms
  • What the standard string class provides and how to use it
  • How to write localized applications
  • What functionality the library provides for file and stream-based I/O
  • What smart pointers are and how to use them to prevent memory leaks
  • How to write safe and efficient multi-threaded code using the C++11 threading libraries

 

CppCon 2015 Grill the Committee

Have you registered for CppCon 2016 in September? Don’t delay – 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:

Grill the Committee

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

What would you like to know about how the C++ Standard happens?

The panel is made up of members of the C++ Standards Committee and the audience asks the questions.

Trip report: Summer ISO C++ standards meeting (Oulu) -- Herb Sutter

A comprehensive trip report from the just-concluded ISO C++ meeting:

Trip report: Summer ISO C++ standards meeting (Oulu)

by Herb Sutter

From the article:

The big news is that C++ is feature-complete, and on time! We added several more features to the C++17 working paper (see next section), then approved the result to be sent out this summer for its major ISO international comment ballot, which is the Committee Draft or “CD” ballot.

... At this meeting, we added several more features into C++17: ...

Competing constructors--Andrzej Krzemieński

We all got some surprises like this:

Competing constructors

By Andrzej Krzemieński

From the article:

We start with a known C++ gotcha:

std::vector<int> v (size_t(4), 2); // parentheses
std::vector<int> u {size_t(4), 2}; // braces
 
assert (v.size() == 4);
assert (u.size() == 2);
 
assert (v[0] == 2); // elements: {2, 2, 2, 2}
assert (u[0] == 4); // elements: {4, 2}

In this post I want to analyze the source of the problem a bit further, and offer some suggestions on class design.

CppCon 2016 teaser video

cppcon2016.PNGJust in time for the Early Bird registration deadline tomorrow, CppCon dropped a new teaser video. Enjoy!

See what previous years' attendees had to say, then come join the festival.

 

C++17, All Final Features from Oulu in a Few Slides

The good news from Oulu is that we approved the publishing of a draft of C++17.

As I changed job between the last Jacksonville and this Oulu meeting, I have been unable to keep up and write my usual update either post-meeting or pre-Oulu, so I thought I would keep it simple and make up for it in this post (although there have been plenty of other blogs) and show you all the details in a slide deck that I have been using as a keynote at recent ADC++, IWOCL 2016, the Amsterdam SG14/C++ users group meeting, and the Chicago STAC 2016 meetings.

https://wongmichael.com/2016/06/29/c17-all-final-features-from-oulu-in-a-few-slides/

If you just want to see all the features going into C++17 other than the Special Math, Parallelism, Library Fundamentals, and Filesystems TS, just go to slides 44-47 which will contain both the Language and Library features with clickable links for you to follow. The features voted in Oulu are on slide 45 for language and 47 for library.

Quick Q: Are `==` and `!=` mutually dependent?

Quick A: They are not, because it is not always true.

Recently on SO:

Are `==` and `!=` mutually dependent?

You would not want the language to automatically rewrite a != b as !(a == b) when a == b returns something other than a bool. And there are a few reasons why you might make it do that.

You may have expression builder objects, where a == b doesn't and isn't intended to perform any comparison, but simply builds some expression node representing a == b.

You may have lazy evaluation, where a == b doesn't and isn't intended to perform any comparison directly, but instead returns some kind of lazy<bool> that can be converted to bool implicitly or explicitly at some later time to actually perform the comparison. Possibly combined with the expression builder objects to allow complete expression optimisation before evaluation.

You may have some custom optional<T> template class, where given optional variables t and u, you want to allow t == u, but make it return optional<bool>.

There's probably more that I didn't think of. And even though in these examples the operation a == b and a != b do both make sense, still a != b isn't the same thing as !(a == b), so separate definitions are needed.

Typedef Literacy--Michael Park

typedef explained!

Typedef Literacy

by Michael Park

From the article:

The typedef declaration provides a way to create an alias for an existing type. For example, we can provide an alias for int called integer like so:

typedef int integer;

I imagine most people have seen such declarations, and they are fairly simple to read. In fact it’s so simple that we may incorrectly conclude that the syntax for typedef is:

typedef <existing_type> <new_type_name>;

CppCon 2015 Using Spirit X3 to Write Parsers--Michael Caisse

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:

Using Spirit X3 to Write Parsers

by Michael Caisse

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

Parsing is a common problem in many domains. The complexity of using a library often pushes developers to ad-hoc solutions utilizing std::string manipulations, regular expressions, or nested if/switch statements. Most “quick hack” implementations are unmaintainable.

Spirit provides a Domain Specific Embedded Language (DSEL) that allows grammars to be described in a natural and declarative manner just like writing PEG or EBNF directly in your C++ code. X3 is the third major release of the Spirit library and improves both compile and run times while simplifying the much of the library.

In this tutorial session you will be introduced to Spirit X3, attribute parsing, and variety of tips to writing efficient and maintainable parsers. We will build a JSON parser during the session to illustrate techniques and usage of the library. This session is applicable toward anyone needing to parse data.