January 2017

(Not) detecting bugs--Andrzej Krzemieński

Undefined behaviour can be dangerous.

(Not) detecting bugs

by Andrzej Krzemieński

From the article:

The following code contains a bug. A developer has spent quite some time looking for the source. The intent of this code is to iterate over two vectors simultaneously, from the first up to the one-before-last element. Thus the most interesting tools that will be employed will be boost::zip_iterator and std::prev.

#include <boost/iterator/zip_iterator.hpp>
#include <boost/tuple/tuple.hpp>
#include <vector>

using zip_iter = boost::zip_iterator<
                   boost::tuple<
                     std::vector<int>::iterator,
                     std::vector<int>::iterator
                   >
                 >;
int main()
{
  std::vector<int> v1 = {1, 2, 3, 4, 0};
  std::vector<int> v2 = {2, 3, 5, 7, 0};
    
  zip_iter beg {boost::make_tuple(v1.begin(), v2.begin())};
  zip_iter end {boost::make_tuple(v1.end(), v2.end())};
  
  auto process = [](zip_iter::reference){};
  std::for_each(beg, std::prev(end), process);
}

Add a const here, delete a const there…--Bruce Dawson

Why constness is important in one article. Can be even better with constexpr.

Add a const here, delete a const there…

by Bruce Dawson

From the article:

I just completed a series of changes that shrunk the Chrome browser’s on-disk size on Windows by over a megabyte, moved about 500 KB of data from its read/write data segments to its read-only data segments, and reduced its private working set by about 200 KB per-process. The amusing thing about this series of changes is that they consisted entirely of removing const from some places, and adding const to others. Compilers be weird...

Generate lambdas for clarity and performance--Björn Fahller

A nice way to avoid code duplication and gain in readability:

Generate lambdas for clarity and performance

by Björn Fahller

From the article:

Higher order functions, functions that operate on other functions or returns functions, are familiar to those who have had some experience with functional programming, but they often seems magical to those who have not. Some of those with experience of using higher order functions have a gut feeling that they are expensive to use and prefer to avoid them...

C++ User Group Meetings in January

The January listing of upcoming User Group meetings!

C++ User Group Meetings in January

by Jens Weller

From the article:

The new year has begun, and as I just returned the listing of the User Group Meetings is a bit late...

Yet still, 37 Meetings in January are listed, 7 of them in Austin, as there is a study group for Modern C++ now.

There are 3 new C++ User Groups: Nashua, NH, Vienna (Qt), Austin (Mentoring & Study Group).

C++ Status at the end of 2016 -- Bartlomiej Filipek

What happened in 2016 in the C++ world?

C++ Status at the end of 2016

by Bartlomiej Filipek

From the article:

Let’s now focus on the main topic from this year.During the ISO meeting in Oulu (June), the Committee accepted the draft for C++17. This is definitely not a minor release since a lot of features were added!

Sorting by indices, part 2—Raymond Chen

It seems a simple problem, yet…

Sorting by indices, part 2

by Raymond Chen

From the article:

Before we dig into the Schwartzian transform, let's look at a more conventional generic way to sort by a key:

template<typename Iter, typename UnaryOperation, typename Compare>
void sort_by(Iter first, Iter last, UnaryOperation op, Compare comp)
{
  std::sort(first, last,
            [&](T& a, T& b) { return comp(op(a), op(b)); });
}

The idea here is that you give a unary operator op that produces a sort key, and we sort the items by that key according to the comparer...

passing functions to functions--Vittorio Romeo

How do you pass functions?

passing functions to functions

by Vittorio Romeo

From the article:

Since the advent of C++11 writing more functional code has become easier. Functional programming patterns and ideas are powerful additions to the C++ developer's huge toolbox. (I recently attended a great introductory talk on them by Phil Nash at the first London C++ Meetup - you can find an older recording here on YouTube.)

In this blog post I'll briefly cover some techniques that can be used to pass functions to other functions and show their impact on the generated assembly at the end...

N4633: 2017-11 Albuquerque WG21 meeting information -- Carter Edwards

A new WG21 paper is available. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N4633

Date: 2017-01-09

2017-11 Albuquerque WG21 meeting information

by Carter Edwards

Excerpt:

Sandia National Laboratories is pleased to host the Fall 2017 WG21 working meeting on November 6-11, 2107 at Albuquerque Marriott Hotel, 2101 Louisiana Blvd NE, Albuquerque, NM 87110...