basics

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;
});

Is Moving Objects Worth the Hassle? -- Andrew Koenig

Koenig's latest just went live at DDJ:

Is Moving Objects Worth the Hassle?

by Andrew Koenig

From the article:

Last week, I discussed how C++ compilers use overloading to decide whether to move or copy an object. This week, I'd like to take a step back and discuss why moving instead of copying is worth doing in the first place.

You might think that this claim needs no justification. After all, copying takes time; so programs that copy a lot of data will be slower than programs that avoid doing so. However, this kind of unthinking optimization can lead to trouble. For example...

The Point of No Return -- bulldozer00

A cute nugget about [[noreturn]]:

The Point of No Return

by bulldozer00

As part of learning the new feature set in C++11, I stumbled upon the weird syntax for the new “attribute” feature: [[ ]]. One of these new C++11 attributes is [[noreturn]]. ...

Quick Q: When should you use constexpr? -- StackOverflow

Quick A: When you want to potentially evaluate a calculation at compile time. You can do much, much more than just "return 5;".

When should you use constexpr capability in C++11?

It seems to me that having a "function that always returns 5" is breaking or diluting the meaning of "calling a function". There must be a reason, or a need for this capability or it wouldn't be in C++11. Why is it there?

// preprocessor.
#define MEANING_OF_LIFE 42
// constants:
const int MeaningOfLife = 42;
// constexpr-function:
constexpr int MeaningOfLife () { return 42; }

It seems to me that if I wrote a function that return a literal value, and I came up to a code-review, someone would tell me, I should then, declare a constant value instead of writing return 5.

C++'s Best Feature -- Andrzej KrzemieĊ„ski

Andrzej's title is not only catchy, but completely correct (we politely disagree with your final disclaimer, sorry Andrzej): Deterministic lifetime with destructors is C++'s best feature, and very underappreciated. Like most wonderful things, you appreciate it most when it's gone, namely when you're using another language where it's absent.

C++'s best feature

by Andrzej Krzemieński

From the article:

C++, if you want to learn all of it, is big, difficult and tricky. If you look at what some people do with it, you might get scared. New features are being added. It takes years to learn every corner of the language.

But you do not need to learn all of it. Effective use of C++ requires only the knowledge of a couple of its essential features. In this post, I am going to write about one C++ feature that I consider one of the most important. The one that makes me choose C++ rather than other popular programming languages. ...

Sometimes You Must Violate an Abstraction to Maintain It -- Andrew Koenig

Koenig explains std::move as, well, just a bit of a fib, really:

Sometimes You Must Violate an Abstraction to Maintain It

by Andrew Koenig

From the article:

What std::move really does is to return its argument as an rvalue reference. In effect, every time we use std::move, we are telling a lie. In this case, by writing std::move(t.s), we are saying that we want to use t.s, but to do so in a way that treats t.s as an rvalue. It is acceptable for us to tell this lie for exactly the same reason that it is acceptable for us to cast t.s to string&& in the previous example: We know that t.s is a member of t, and t really refers to an rvalue in our caller's context.

We can tell such lies any time we are willing to take responsibility for the consequences. ...

C++11/14 Training Materials -- Scott Meyers

meyers-newcppmaterials.PNGC++14 is still very much a draft -- it only became feature-complete in April and is now in its primary comment ballot. But interest in this new standard is high, with a restarted "Guru of the Week" series focusing on C++14 and now Scott Meyers has produced the first book-like materials that include significant coverage of C++14.

C++11 Training Materials Updated -- Now With C++14 Info!

For the seventh time since originally releasing them over three years ago, I've updated my annotated training materials for "The New C++". Until this update, "the new C++" referred to C++11, but with this revision, I'm including treatment of several features from draft C++14 that I believe will make it into the new new standard. As far as I know, this makes my training materials the first "book-like" publication that covers features in C++14.