June 2013

C++11: The Future Is Here -- Bjarne Stroustrup

stroustrup-accu2013.PNGStroustrup's ACCU keynote video is now available online.

C++11: The Future Is Here

Bjarne Stroustrup

Summary: Bjarne Stroustrup keynotes on what C++ is in general, how C++11 makes simple things even simpler, resource management, generic programming, and concurrency.

Regular Expressions 101: Regex in C++11 -- Brian Overland

overland_brian_c.jpgNew at InformIT:

Regular Expressions 101: Regex in C++11

by Brian Overland

From the article:

... You don't really need to know how it works. In fact, you only need to know a few things:

  • The regular expression grammar used by the C++11 regex library functions
  • The relevant C++11 functions and how to call them

The first part of this article focuses on the default regex grammar used in C++11: the ECMAScript grammar. You'll generally want to use ECMAScript, because it provides powerful capabilities while being easy to use. For simplicity, I'll focus on this grammar. ...

GotW #93 Solution: Auto Variables, Part 2 -- Herb Sutter

The solution to the latest GotW problem is now available:

GotW #93 Solution: Auto Variables, Part 2

by Herb Sutter

From the article:

As you worked through these cases, perhaps you noticed a pattern: The cases are mostly very different, but what they have in common is that they illustrate reason after reason motivating why (and how) to use auto to declare variables.

Let’s dig in and see...

When Is It Safe to Move an Object Instead of Copying It? -- Andrew Koenig

andy1.jpgARK's latest, hot off the press:

When Is It Safe to Move an Object Instead of Copying It?

by Andrew Koenig

From the article:

Last week, I introduced the idea of moving objects, and explained that moving an object is usually better than copying it if the original is not going to be used again. Now I'd like to explain how the compiler can figure out during compilation when to move objects instead of copying them.

As is so often the case with such problems, the obvious solution is wrong. Consider this code fragment: ...

Quick Q: What type to return from a property-style "getter"? -- StackOverflow

Quick A: Reference to const.

c++11 -- Ownership and getters

I'm new to C++ and I have troubles wrapping my head around ownership, specifically with a getter. Here's some example code:

class GameObject {
public:
  Transform *transform();
private:
  Transform _transform;
};

I guess a raw pointer is unsafe to use as someone could access it later when the object doesn't exist anymore?

  1. So I thought about using a unique_ptr for the transform member, since GameObject is the only one that owns the transform. But I can't return that from the getter, can I? But then again, why would I ever use a unique_ptr in the first place instead of adding it as a member like above?
  2. So why not use a shared_ptr? It just seems wrong to me, I don't want to share ownership, GameObject is the owner and others may access it...
  3. So what is it? A reference? I guess shared_ptr seems the wisest choice, since others could safely keep a reference to transform, but what good is that if the enclosing GameObject got destroyed, rendering the transform useless? I'm probably just thinking about ownership the wrong wrong way here but every way seems wrong to me. Thanks for your help.

Core C++, 8 and 9: From do-while to variadic array sorter to lambdas -- Stephan T. Lavavej

core-8-9.PNGThe two latest C++ lectures by Stephan T. Lavavej, the eponymous STL, are now available:

Core C++, 8 of n

In part 8, STL digs into the do-while loop, casts, one definition rule (ODR), and his variadic template array sorter. There is a lot of information in this episode, so get comfortable, tune in, and learn.

Core C++, 9 of n

In part 9, STL digs into lambdas and other expressions. Lambdas are very useful and you've no doubt been enjoying them in your modern C++ programming. As you can imagine, STL will go deep and teach you things about lambdas that you may not know. You'll also learn a lot about order of precedence and associativity for expressions in only the way Stephan can teach you (thorough treatment). Tune in.

C++Now 2013 Keynotes now available

The keynote addresses for C++Now 2013 are now available.

 

Dan Quinlan: C++ Use in High Performance Computing Within DOE: Past and Future

 

Chandler Carruth: Optimizing the Emergent Structures of C++

We are confronted today with the increasing complexity of our C++ software systems. To manage this complexity and build larger applications and systems, C++ strives to form emergent structures (often found in nature, such as snowflakes' symmetrical structures), where simple patterns combine to form a remarkably complex and powerful system. These structures provide both a means to limit the complexity of each component and the essential economies of scale we rely on when developing software.

From handheld devices to warehouse-sized data centers, motivated by smaller devices and increased concerns over power consumption, we are relying upon C++ to deliver these complex systems with unmatched efficiency. Our optimizing compilers today are more important than ever before and are utterly opaque to most practicing programmers. Compounding matters, the very emergent structures which allow C++ systems to scale for humans often provide unique and unsolved challenges to optimization.

In this talk, I will start with a brief overview of how modern optimizing compilers work with C++ code at a very high level. I will then walk through the specific structures and patterns of C++ code, which are at the core of forming emergent structures out of simple, elegant elements. I will also address how these interactions can be effectively modeled and analyzed by a compiler to produce efficient final programs. All of this will be illustrated by a collection of real world case studies, which are broadly applicable and show up throughout modern C++ code bases. My goal is to give a framework for understanding these interactions both in the C++ code and the optimizing compiler, so that programmers are aware of the implications posed by these patterns. Finally, I will introduce a set of principles and techniques for designing and implementing C++ programs and libraries to specifically clear the way for modern optimizers while retaining the simplicity of each component and the power of the combined whole.

Stanley Lippman: yet another paradigm shift (yaps) - a Meta4 model of concurrency

We'll discuss language life cycles, particularly as they apply to C++, from a peek at some of the very early ideas and technology behind C++ to a proposal for the next step: yet another paradigm shift, not a evolution or revolution but simply a synchronizing of meta4layers — using fertilization of the multi-cell organism as an isomorph.

 

Quick Q: In a function template, why pass const T& vs. T&&? -- StackOverflow

Quick A: Because you want to not change the argument, or you want to forward it, respectively.

c++ rvalue reference and const qualifier

Among the many benefits of const qualification is to make an API more understandable, example:

template<typename T> int function1(T const& in);
// clearly, the input won’t change through function1

With the introduction of rvalue references, one can benefit from perfect forwarding but often const qualifiers are removed, example:

template<typename T> int function2(T&& in);
// can explicitly forward the input if it's an rvalue

Apart from documentation, is there a good way to describe that function2 won’t change its input?