Understanding the New Set and Map Containers in the C++11 Standard Library -- S Clamage and D Gove

On the Oracle Tech Network, a nice reminder of the still-"new"-to-some hash-based containers, co-authored by the chair of the U.S. C++ standards committee:

Understanding the New Set and Map Containers in the C++11 Standard Library

by Steve Clamage and Darryl Gove

From the article:

One of the areas in the new C++ standard that has seen the most enhancement is the Standard Library. The functionality that is most likely to be immediately useful to developers is the additions to the container classes. This article describes the new set and map containers.

Parallel STL: Democratizing Parallelism in C++ -- Artur Laksberg

Today on VCblog:

Parallel STL: Democratizing Parallelism in C++

by Artur Laksberg

From the article:

Over the last few years, a group of software engineers from Intel, Microsoft and NVidia have worked together on a proposal for the ISO C++ Standard known as the "Parallel STL".

This proposal builds on the experience of these three companies building parallel libraries for their platforms -- the Threading Building Blocks (Intel), PPL and C++ AMP (Microsoft) and Thrust (NVidia). All these libraries have a common trait -- they allow developers to perform common parallel operations on generic containers. Naturally, this aligns very well with the goals of the C++ Standard Template Library.

All three companies are working on their implementations of the proposal. Today, we're pleased to announce that Microsoft has made the prototype of the proposal available as an open source project at ParallelSTL.codeplex.com.

We encourage everyone to head over to our CodePlex site and check it out. The proposal has been approved to be the foundation for the "Parallelism Technical Specification" by the ISO C++ Standards Committee ...

Quick Q: Why does this function take a parameter by value? -- StackOverflow

A classic on SO:

Why do we copy then move?

I saw code somewhere in which someone decided to copy an object and subsequently move it to a data member of a class. This left me in confusion in that I thought the whole point of moving was to avoid copying. Here is the example:

struct S
{
    S(std::string str) : data(std::move(str))
    {}
};

Here are my questions:

  • Why aren't we taking an rvalue-reference to str?
  • Won't a copy be expensive, especially given something like std::string?
  • What would be the reason for the author to decide to make a copy then a move?
  • When should I do this myself?

The standard way of converting between numbers and strings in C++11 -- Marius Bancila

Quick: Would you resort to stringstream? But that's so C++98... and so hard.

More people need to know about to_string and its cousins. Marius Bancila takes us for a short tour:

The standard way of converting between numbers and strings in C++11

by Marius Bancila

From the article:

C++11 provides several standard functions for converting numbers to strings and strings to numbers, all of them available in the <string> header.

For converting numbers to strings there are two new overloaded functions: to_string() and to_wstring(). They take one argument of various numeric types (int, long, long long, double, long double, etc.) and return either a std::string or a std::wstring with the number converted to text. ...

For the other way around of converting strings to numbers there are several overloaded methods (taking either a std::string or a std::wstring): ...

Ponder the use of unique_ptr to enforce the Rule of Zero -- Marco Arena

Marco Arena points out an important difference between shared_ptr and unique_ptr regarding polymorphic deletion. The article also shows two ways to equip unique_ptr with a type-erased deleter, one with no usage of dynamic dispatching.

Ponder the use of unique_ptr to enforce the Rule of Zero

by Marco Arena

I read the article "Enforcing the Rule of Zero" from latest Overload (of ACCU) and I'd like to point out something that I misapprehended at a first reading. ... a clever point the author underlines is about polymorphic deletion: what to do when we want to support polymorphic deletion, or when our classes have virtual functions? ...

Then the author suggests to use a shared_ptr: ...

CppCon 2014 super early bird almost sold out -- ~20 tickets left

cppcon-144.PNGIf you've been thinking of registering for CppCon, you can save by doing it in the next couple of days. Over at CppCon.org, Boris Kolpackov reports:

Super Early Bird Last Chance

In the past couple of weeks a lot of C++ enthusiasts have registered for CppCon 2014 and as a result we only have about 20 super early bird entries left. If you are planning to attend, this is your last chance to register at the most affordable price.

After the limited Super Early Bird is full, Early Bird registration will be available until the end of June. Student registrations are also available at a heavily subsidized rate to ensure students can take advantage of the program.

See also the Call For Submissions to see the kinds of topics that you can expect to see covered.

 

Common Optimizations -- Andrzej KrzemieĊ„ski

Today from the desk of Andrzej:

Common Optimizations

by Andrzej Krzemieński

From the article:

Language designers, compiler and library vendors make a great effort to make your programs run faster and faster. This post is a tour of some common performance optimizations in C++.

Consider the following code that deals with std::string: ...

Parsing XML at the Speed of Light--Arseny Kapoulkine

Some high-performance techniques that you an use for more than just parsing, including this week's darling of memory management:

Parsing XML at the Speed of Light

a chapter from "The Performance of Open Source Applications"
by Arseny Kapoulkine

From the chapter:

This chapter describes various performance tricks that allowed the author to write a very high-performing parser in C++: pugixml. While the techniques were used for an XML parser, most of them can be applied to parsers of other formats or even unrelated software (e.g., memory management algorithms are widely applicable beyond parsers). ...

Optimizing software is hard. In order to be successful, optimization efforts almost always involve a combination of low-level micro-optimizations, high-level performance-oriented design decisions, careful algorithm selection and tuning, balancing among memory, performance, implementation complexity, and more. Pugixml is an example of a library that needs all of these approaches to deliver a very fast production-ready XML parser–even though compromises had to be made to achieve this. A lot of the implementation details can be adapted to different projects and tasks, be it another parsing library or something else entirely.

Continue reading...

What does [this] mean in C++? -- StackOverflow

Recently on SO:

What does "[ this ]" mean in C++?

When I was reading the Cocos2dx 3.0 API, I found something like this:

auto listener = [this](Event* event){
    auto keyboardEvent = static_cast<EventKeyboard*>(event);
    if (keyboardEvent->_isPressed)
    {
        if (onKeyPressed != nullptr)
            onKeyPressed(keyboardEvent->_keyCode, event);
    }
    else
    {
        if (onKeyReleased != nullptr)
            onKeyReleased(keyboardEvent->_keyCode, event);
    }
};

What does [this] mean? Is this new syntax in C++11?

Overload 120 is now available

overload-120.PNGOverload 120 is now available. It contains the following C++-related articles, and more:

 

Overload 120

Enforcing the Rule of Zero

Juan Alday considers how the new standards have affected a common rule.

Search with CppCheck

Martin Moene tries a more powerful code search tool.

Size Matters

 

Sergey Ignatchenko and Dmytro Ivanchykhin compare 32-bit and 64-bit programs.

Windows 64-bit Calling Conventions

Roger Orr sees how the stack organisation has changed.