Sometimes you get things wrong--Marshall Clow

What is the best thing to return?

Sometimes you get things wrong

by Marshall Clow

From the article:

A few years ago, Sean Parent challenged me to provide an implementation of Boyer-Moore searching in C++. I did that, first in boost and then, later as part of the proposed Library Fundamentals Technical Specification.

The idea here is that you have a searcher object, which encapsulates the actual searching. You construct it with the pattern that you want to search for, and then you call the searchers operator() with the corpus that you want to search, and it will return to you the start of the pattern in the corpus, if it exists, and the end of the corpus, if it does not (this is the same set of rules that std::search follows).

But this weekend I realized that this is not the right thing to return. The searcher (and std::search for that matter) should return a “range” (ok, a pair of iterators) denoting the beginning and end of the pattern in the corpus. (Yes, you can get the end of the pattern by incrementing the returned iterator by the length of the pattern, but that’s an O(N) operation if you only have forward iterators...

Fundamentals of Type-Dependent Code Reuse - Mark Isaacson - NDC Oslo 2015

From NDC Oslo 2015:

Fundamentals of Type-Dependent Code Reuse

by Mark Isaacson

About the video:

This talk surveys different code reuse problems that can be solved by leveraging type information. Mark talks about how you can optimize your algorithms so that certain types use a "fast path", all while hiding that complexity from your users. He also talks about various ways to create "opt-in" functions for your classes. The talk is accessible to novices but builds gradually to complex ideas, including a theoretical C++17 "Mixer" class that allows users to add arbitrary functions to any type, including ints, on an instance by instance granularity.

build2 — C++ Build Toolchain

build2 is an open source, cross-platform toolchain for building and packaging C++ code. It includes a build system, package manager, and repository web interface. There is also cppget.org, a public repository of open source C++ packages.

build2 — C++ Build Toolchain

From the announcement:

This is the first alpha release and currently it is more of a technology preview rather than anything that is ready for production. It has been tested on various Linux'es, Mac OS, and FreeBSD. There is no Windows support yet (but cross-compilation is supported).

P0225: Why I want Concepts, and why I want them sooner rather than later -- Ville Voutilainen

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: P0225R0

Date: 2016-02-05

Why I want Concepts, and why I want them sooner rather than later

by Ville Voutilainen

Excerpt:

This paper provides highly-opinionated statements, anecdotes and personal opinions explaining why the author thinks Concepts should go into C++17 even if no Conceptified standard library parts are included in C++17.

Raw loops vs STL algorithms

A new post on the Meeting C++ blog, this time on <algorithm>

Raw loops vs. STL algorithms

by Jens Weller

From the article:

Since last week I am working on my CMS for static HTML pages again, and so the series about Building applications with Qt and boost continues. Today its about using STL algorithms, or how Sean Parent once said "no raw loops!". Now, I am not Sean Parent, and not event the implementers of the STL are perfect. Most code which I write is application code, which then powers Meeting C++. Also, I don't know all STL algorithms, and some times its just to tempting to write a little loop instead of searching the STL for the specific algorithm. Yesterday I had such a case.

N4573: February 2017 WG21 Meeting -- Tom Plum

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: N4573

Date: 2016-02-02

February 2017 WG21 Meeting

by Tom Plum

Excerpt:

The February 2017 WG21 meeting is sponsored by Plum Hall and the Standard C++ Foundation. The meeting will take place at the Royal Kona Resort, in Kailua-Kona Hawaii, Monday Feb 27 to Saturday Mar 04.

Emulating C++17 Structured Bindings in C++14--John Bandela

How to use tuple return values with ease?

Emulating C++17 Structured Bindings in C++14

by John Bandela

From the article:

Bjarne Stroustrup back in Novemeber wrote a nice progress report, available here, of the Kona meeting. One of the proposals considered is called structured binding. The proposal addresses one of the inconveniences of returning multiple values from a function using tuples. While, it is very easy for a function to return multiple values, it is harder for the caller to use them. Here is an example from the write up.

consider the following function

tuple<T1,T2,T3> f() { /*...*/ return make_tuple(a,b,c); }

If we want to split the tuple into variables without specifying the type, we have to do this;

auto t = f();
auto x = get<1>(t);
auto y = get<2>(t);
auto z = get<3>(t);

The proposal puts forth the following syntax instead

auto {x,y,z} = f();               // x has type T1, y has type T2, z has type T3

I am excited for this feature, and for C++17 in general. While waiting for C++17, I decided to see how close I could get with C++14. Here is the result.

auto r = AUTO_TIE(x,y,z) = f();               // x has type T1, y has type T2, z has type T3

// Unlike the C++17 feature, you need to use r.x instead of just x
std::cout << r.x << "," << r.y << "," << r.z << "\n";