Home > C++11 > Moving, Initializing, And Hotdogging

Moving, Initializing, And Hotdogging

In an interview with C++ creator Bjarne Stroustrup, Danny Kalev asked Bjarne several questions about the major features being incorporated into the venerable C++ language via the C++0x standardization effort. Here’s one such Q+A exchange:

I know, I know. The “*” should be a “+” in the free function declaration box above. But does the typo really detract from the message being conveyed?

So, how hard is it to write a move constructor implementation? It’s as hard as this:

Notice how the lower level reference-to-a-reference (i.e. rvalue reference)¬† feature in the Matrix move constructor enables the higher level “move” feature to be easily written. This capability to move big stuff around instead of copying the behemoth will be a great addition to the language, especially to library writers, no?

Bjarne’s examples of the new “uniform and universal initialization” C++0x feature jacked me up too:

We can use the {…} notation for every initialization and wherever we initialize an X with {v} we get the same resulting value. That’s a major improvement over C++98’s non-uniform set of alternatives using the =v, ={v}, and (v) notations:

With any new and powerful tool, there’s always the danger of “hotdoggers” conniving to show how much smarter than you they are. Here’s a typically wise and insightful, and universal quote from Bjarne on the topic:

Before we get to benefit from the simplifications offered by C++0x, we may go through a period where too many people try to show off their cleverness by enumerating language rules and digging into the most obscure corners. That can do harm.

You’re not one of “those” people are you? I’m not. Luckily, I ain’t smart enough to be a hotdogger. But if I was brilliant…….

Note: I know that the code above is really C, but it was the first googled C++ example I stumbled across.

  1. November 7, 2014 at 6:03 am
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: