July 2013

Why Would You Ever Pass a Container By Value? -- Andrew Koenig

From the desk of ARK:

Why Would You Ever Pass a Container By Value?

by Andrew Koenig

From the article:

Consider two fundamental features of C++: functions and references. Which shall we teach first?

If we teach references first, there is the problem of coming up with interesting example programs that use references but completely avoid user-defined functions. This is hard to do because the most common use of references is as function parameters — so it's probably easier to teach functions first.

However, if we teach functions before we teach references, then every function we write must accept its arguments by value — references not yet being available as an alternative...

HPX version 0.9.6 released -- Stellar Group, LSU

stellar-group.PNGThe Stellar Group at Louisiana State University has released version 0.9.6 of High Performance Parallex (HPX) for Linux, MacOS, Windows, and Android.

HPX V0.9.6 Released

The STE||AR Group is proud to announce the sixth formal release of HPX (V0.9.6). ...

From the announcement:

In this release we have made several significant changes:

  • Consolidated API to be aligned with the C++11 (and the future C++14) Standard
  • Implemented a distributed version of our Active Global Address Space (AGAS)
  • Ported HPX to the Xeon-Phi device
  • Added support for the SLURM scheduling system
  • Improved the performance counter framework
  • Added a distributed version of the Active Global Address Space (AGAS)
  • Added parcel (message) compression and parcel coalescing systems
  • Allow different scheduling polices for different parts of code with experimental executors API
  • Added experimental security support on the locality level
  • Created a native transport layer on top of Infiniband networks
  • Created a native transport layer on top of low level MPI functions
  • Added an experimental tuple-space object

Contextually Converted to Bool -- Chris Sharpe

A nice writeup of when this "it just works the way you expect" feature kicks in:

Contextually converted to bool

by Chris Sharpe

From the article:

Something I found mildly surprising about C++11 is that this works:

#include <iostream>

struct Testable
{
    explicit operator bool() const { return true; }
};

int main()
{
    Testable t;
    if (t)
        std::cout << "Converted to true!\n";
}

That is, it compiles and prints Converted to true!.

The new bit here is the explicit keyword. When I first saw an example like this, I expected to have to write

if (bool( t )) // ...

[...]

Quick Q: Why do I have to std::move a variable that is already a &&? -- StackOverflow

Today on SO, a frequently asked question and a nicely summed up answer:

std::move on a variable which already is T&&

On the page http://msdn.microsoft.com/en-us/library/dd293665.aspx Microsoft has an example on how to write a move constructor. It is essentially of the form:

MyClass::MyClass(MyClass&& lhs)
{
    *this = std::move(lhs);
}

I have tried and std::move really is required here, but why? I thought the only thing move did was to convert to T&&. But lhs is already of type MyClass&&, is it not?

Some Notes on C++11 Lambda Functions -- Ranju V.

ranjuv.jpgHere's a nice lambda synopsis with some usage notes.

Some notes on C++11 lambda functions

by Ranju V.

From the article:

Bjarne Stroustrup says that C++11, which is the latest ratified revision of the C++ standard, “feels like a new language”.  I think lambda functions are a big part of what makes the language feel so very different from C++03.  Lambda functions basically allow you to do things like this:

vector<int> nums { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
auto evens = count_if(begin(nums), end(nums), [](int num) {
    return (num % 2) == 0;
});

GoingNative day 1 and 2 talks announced

gn13-1-2.pngGoingNative 2013 will be held on September 4-6. Register soon -- in-room space is limited.

The day 1 and 2 talks have now been posted:

Opening Keynote (Bjarne Stroustrup, Texas A&M University)

Bjarne Stroustrup, creator of C++, will open the show.

C++ Seasoning (Sean Parent, Adobe)

A look at many of the new features in C++ and a couple of old features you may not have known about. With the goal of correctness in mind, we’ll see how to utilize these features to create simple, clear, and beautiful code. Just a little pinch can really spice things up.

Writing Quick Code in C++, Quickly (Andrei Alexandrescu, Facebook)

Contemporary computer architectures make it possible for slow code to work reasonably well. They also make it difficult to write really fast code that exploits the CPU amenities to their fullest. And the smart money is on fast code -- we’re running out of cool things to do with slow code, and the battle will be on doing really interesting and challenging things at the envelope of what the computing fabric endures.

So how to write quick code, quickly? Turns out it’s quite difficult because today’s complex architectures defy simple rules to be applied everywhere. It is not uncommon that innocuous high-level artifacts have a surprisingly high impact on the bottom line of an application’s run time (and power consumed).

This talk is an attempt to set forth a few pieces of tactical advice for writing quick code in C++. Applying these is not guaranteed to produce optimal code, but is likely to put it reasonably within the ballpark.

These tips are based on practical experience but also motivated by the inner workings of modern CPUs.

Don’t Help the Compiler (Stephan T. Lavavej, Microsoft)

C++ has powerful rules for dealing with low-level program structure.  Before a program is ever executed, the compiler determines valuable information about every expression in the source code.  The compiler understands exactly how long each object's resources will be needed (lifetime), whether each expression refers to an object that the program has no other way of accessing (rvalueness), and what operations can be performed on each object (type).  Using examples from C++98 through C++14, this presentation will demonstrate how to write code that works with the compiler's knowledge to increase robustness, efficiency, and clarity.  This presentation will also demonstrate the horrible things that happen when programmers think they can do tasks that are better left to compilers.

Day 1 Panel (all speakers)

Interactive panel. Topic TBD. Attendee-driven Q&A.

Day 2 Keynote: One C++ (Herb Sutter, Microsoft)

Herb Sutter, language architect of Visual C++ and Chairman of the ISO C++ Committee, opens Day 2 with a brand new talk, "One C++."

An Effective C++11/14 Sampler (Scott Meyers)

After years of intensive study (first of C++0x, then of C++11, and most recently of C++14), Scott thinks he finally has a clue. About the effective use of C++11, that is (including C++14 revisions). At last year’s Going Native, Herb Sutter predicted that Scott would produce a new version of Effective C++ in the 2013-14 time frame, and Scott’s working on proving him almost right. Rather than revise Effective C++, Scott decided to write a new book that focuses exclusively on C++11/14: on the things the experts almost always do (or almost always avoid doing) to produce clear, efficient, effective code. In this presentation, Scott will present a taste of the Items he expects to include in Effective C++11/14. If all goes as planned, he’ll also solicit your help in choosing a cover for the book.

C++14: Through the Looking Glass (Michael Wong, IBM)

“The time has come,” the ISO said,
“To talk of many things: 
Of move-capture -- and literals --
Of making lambdas sing --
And why deduction is so hot --
nd if digits should grow wings?”

So have you heard of the next C++ Standard? No, it is not C++11. Even though C++11 has just been ratified, C++14 will likely replace C++11 by next year. By now, we have enough experience with C++11 to know where we are missing various fingers and toes such as:

  • Why do we not have move capture in lambdas? 
  • How about some real user-defined literal suffixes? 
  • Why did we stop with monomorphic lambdas? 
  • If lambda returns can be deduced, why not normal functions? 
  • Could we get digit separators?

C++14 will be more than a bug-fix release, and will contain some important enhancements on top of C++11. It will remove some of the major annoyances from C++11, that we already know of. But more importantly, how will this change the language, library and some important idioms?

The Care and Feeding of C++’s Dragons (Chandler Carruth, Google)

Last year I described C++ as bearing the cautionary label ‘Here Be Dragons.’ And yet we’re all still writing C++ because it is the best programming language for the problems we face. In turn, we need a strategy to deal with the “dragons” that reside in large C++ code bases. The Dragon Book (my old compiler textbook) taught about a collection of tools to address the complexity of compiler design, and while our challenge is somewhat different, the approach remains the same. When a mere mortal programmer ventures forth to battle the complexity of large software systems in C++, they’re going to need some really good tools to help them. At Google, we’ve been building up a platform of such tools. I will introduce the platform and toolset, and show how to use them to write fast and correct C++ code, quickly and correctly.

I will also give a peek into the future of the next generation of tools we’re working on and some of the really interesting changes to C++ that are coming in the next few years to help both programmers and these tools be ever more effective.


Day 2 Panel (all speakers)

Interactive panel. Topic TBD. Attendee-driven Q&A.

Boost Your Productivity with C++11 and Templates (Sep 9-13, Oct 7-11) -- Peter Gottschling

peter-gottschling.jpgThis course is being held in English and German:

Boost Your Productivity with C++11 and Templates

by Peter Gottschling

  • September 9-13 (German)
  • October 7-11 (English)

Abstract:

Templates (generic programming)

  • Function templates
  • Class templates
  • Variadic Templates (C++11)
  • Concepts
  • Specialization
  • Template arguments that are not types
  • Functors
  • Lambda functions (C++11)

Standard Template Library

  • Iterator concept
  • Containers
  • Functions
  • Meta-programming
  • Let the compiler compute
  • Providing type informations
  • Auto and decltype (C++11)
  • Const-adaptive classes
  • Expression templates

Other advanced and new techniques

  • Calling functions from derived classes without overhead
  • RValues and move semantics (C++11)
  • Initialization lists (C++11)
  • New for-loops (C++11)

Peter Gottschling is author of the Matrix Template Library 4, co-author of the Boost Graph Library and other scientific libraries. He is vice-chair of DIN's programming language group and head of the German delegation in the ISO committee for C++ standardization. He is managing director of SimuNova and taught C++ at TU Dresden, TU Berlin and Indiana University.

Intel Concurrent Collections for C++ 0.9 now supports Xeon Phi on Windows and Linux

intel.png

Note that some of these concurrent collections are also currently being proposed for ISO standardization.

From the announcement:

Intel Releases New Version of  Intel® Concurrent Collections for C++

Intel released a new version of Intel® Concurrent Collections for C++, a library that helps developers write and tune parallel software. Now with Version 0.9, computers powered by Intel® Xeon Phi™ co-processors are supported and can experience unified programming in the same seamless way that single Intel multi-core workstations and clusters of workstations have experienced with earlier versions. Additionally, its tuning layer was extended, giving developers even easier control over the execution of their application, offering greater potential for performance, scalability and productivity.

Intel Concurrent Collections for C++ is available for Windows and Linux as a free download through the Intel Software Network.