Articles & Books

Quick Q: How can I make my constructor take a list of things, like map and vector? -- StackOverflow

Quick A: By having your constructor take an initializer_list<> of the appropriate type.

Today on StackOverflow:

Constructor similar to std::map or std::vector in a class

I'm creating a class and I want to know how to create a constructor similar to the std::map or std::vector style.

std::map<std::string, std::string> map = {
    {"foo", "bar"},
    {"biz", "buz"},
    {"bez", "boz"}
};

The difference is that I don't want my class to ask for types that wants to accept, just like std::map does.

std::map<std::string, std::string>

I want my class to accept that style of arguments:

{
    {"foo", "bar"},
    {"biz", "buz"},
    {"bez", "boz"}
};

But with defined type. (std::string, Typer)

The 'Typer' is a class that I will insert as value on the std::map.

Thank you.

Clang 3.4 and C++14

With the technical completion of C++14 (we think) reported on Monday, we'd like to link to this recent post for your Friday reading pleasure to recap some of the features of C++14.

There are other articles summarizing C++14 features, but some of the short code examples in this one go beyond what we've seen posted elsewhere and are quite interesting. For example, check out primes.

Clang 3.4 and C++14

by Scott Prager

From the article:

With each new release, gcc and clang add on more C++11 and C++14 features. While clang has been behind on some features, though ahead on others, they now claim to have C++1y all worked out...

Range Concepts, Part 2 of 4: Infinite Ranges

The second part of Eric Nieblers Series about ranges:

Range Concepts, Part 2 of 4: Infinite Ranges

By Eric Niebler

From the Article:

In the last post, I tried to make delimited ranges fit into the STL and found the result unsatisfying. This time around I’ll be trying the same thing with infinite ranges and will sadly be reaching the same conclusion. But the exercise will point the way toward an uber-Range concept that will subsume delimited ranges, infinite ranges, and STL-ish pair-o’-iterator ranges.

Range Concepts, Part 1 of 4: Delimited Ranges

The start on a series about ranges from Eric Niebler:

Range Concepts, Part 1 of 4: Delimited Ranges

By Eric Niebler

From the Article:

I’ve been digging into ranges recently, and I’m finding them to be more than just a pair of iterators. In a series of posts, I’ll be expanding the notion of what a range is to cover some kinds of ranges not easily or efficiently expressible within the STL today: delimited ranges and infinite ranges. This post deals with the problems of representing delimited ranges with STL iterators.

Find the Bug -- Andrzej Krzemieński

Can you spot the bug?

Find the Bug

by Andrzej Krzemieński

From the article:

Today, let's take a short test. Find what is likely to be a bug in the following code and suggest how to fix it.

void Catalogue::populate(vector<string> const& names)
{
  vec_.clear();
  vec_.resize(names.size());

  for (size_t i = 0; i < names.size(); ++i)
    vec_[i] = make_unique<Entry>(names[i]);
}

C++ Papers for Issaquah - Library, Graphics, Networking, Numerics and Undefined Behavior

This is the last part in the series for Issaquah, and its the most diverse:

C++ Papers for Issaquah - Library, Graphics, Networking, Numerics & Undefined Behavior

by Jens Weller

From the Article:

The 4th and last part about the C++ Papers for Issaquah. I already covered the first batch of proposals from the Library subgroup in the previous part, now its all about papers from Library, Graphics, Networking, Numerics and Undefined Behavior. A very diverse part.

C++ Papers for Issaquah - Library I

The third part of my series about the papers for Issaquah is about the first batch of library proposals

C++ Papers for Issaquah - Library I

by Jens Weller

From the article:

The 3rd part of the C++ papers for Issaquah series will be about the library proposals. The last part covered the papers from concepts, database and evolution. There are a lot of proposals from the library group, and I think some of them are the most interesting, as they don't have any impact on the core language.

Quick Q: What's the difference between std::merge and std::inplace_merge? -- StackOverflow

Quick A: "Inplace" can deal with overlapping ranges, but will take either more space or more time.

Today on StackOverflow:

Difference between std::merge and std::inplace_merge?

What is the difference between std::merge and std::inplace_merge in terms of complexity and result when it is executed on two consecutive ranges with elements that are all different ? (I am not a native english speaker and I am not sure to clearly understand what "inplace" means)