basics

C++11 Rocks: Visual Studio 2012 Edition -- Alex Korban

Alex Korban has written a nice e-book that covers the parts of C++11 available in Visual Studio, including documenting limitations and bugs while still focusing on how using the C++11 features makes code cleaner, safer, and faster into the bargain.

The Visual Studio 2012 edition is now in beta. See the table of contents for what's covered, and a free sample to check out the style.

C++11 Rocks: Visual Studio 2012 Edition

by Alex Korban

Highlights from the description:

Visual Studio 2012 gives you the opportunity to use C++11 features to make your code significantly cleaner and easier to read, and to improve performance as well.

But which features are there? Are they ready for use in production code? ... 

You can master the C++11 features in VS2012 with this book. It’s laser focused on C++11, Visual Studio 2012, and nothing else. You’ll quickly get in-depth knowledge of the stuff you need to know.

You’ll learn easily with tons of examples. I spent a lot of time researching and testing, and as a result the book details many C++11 bugs and cases of non-standard behavior in Visual Studio.

Continue reading...

C++ Training at All Levels -- Leor Zolman

On-Site C++ Training at All Levels

by industry veteran Leor Zolman

 

Note: For a limited time, any 4- or 5-day training includes the C++11 Overview.

 

Our C++ and C seminars have been designed by some of the best-known, most effective C++ educators practicing today. In addition to materials created by Leor our C++ training repertoire features courses licensed from and supported by industry leaders Dan Saks and Stephen C. Dewhurst.

A Whirlwind Overview of C++11 (1/2-day, author: Leor Zolman)

Advanced C++  (Author: Stephen C. Dewhurst)

Effective C++ (3-, 4- and 5-day versions of courseware by Scott Meyers based on his books)

An Effective Introduction to the Standard Template Library (STL) (Author: Scott Meyers)

C++ for Non-C Programmers (Author: Leor Zolman)

C++ and Object-Oriented Programming (a.k.a. C++ for C Programmers). (Author: Dan Saks)

A sample unit of any course is available upon request.

Contact us today for more information or to schedule an on-site training at your location!

Quick Q: When should you make a type non-movable in C++11? -- StackOverflow

So C++11 has these cool move semantics... but when would you not implement move construction and move assignment for your type?

When to make a type non-movable in C++11?

I was surprised this didn't show up in my search results, I thought someone would've asked this before, given the usefulness of move semantics in C++11:

When do I have to (or is it a good idea for me to) make a class non-movable in C++11?

(Reasons other than compatibility issues with existing code, that is.)

When does a constexpr function get evaluated at compile time? -- StackOverflow

Here's a common question about constexpr...

A suggestion: As of this writing the more correct and useful (and simpler) answer K-ballo's, which was not selected as best -- please upvote K-ballo and help approve the pending edit that improves it. Thanks.

When does a constexpr function get evaluated at compile time?

Since it is possible that a function declared as constexpr can be called during run-time, under which criteria does the compiler decide whether to compute it at compile-time or during runtime?

 

template<typename base_t, typename expo_t>
constexpr base_t POW(base_t base, expo_t expo)
{
    return (expo != 0 )? base * POW(base, expo -1) : 1;
}

int main(int argc, char** argv)
{
    int i = 0;
    std::cin >> i;
    std::cout << POW(i, 2) << std::endl;
    return 0;
}

 

In this case, i is unknown at compile-time, which is probably the reason why the compiler treats POW() as a regular function which is called at runtime. This dynamic however, as convenient as it may appear to be, has some impractical implications. For instance, could there be a case where I would like the compiler to compute a constexpr function during compile-time, where the compiler decides to treat it as a normal function instead, when it would have worked during compile-time as well? Are there any known common pitfalls?

Quick Q: Is it still bad practice to return a vector from a function?

 

Here's another FAQ about modern C++11 style, and how C++11 is simpler than classic C++, including that this affects how we design our interfaces to make them simpler and easier to read and use.

However, be sure to read through the comments, because they cover several considerations including when it's safe to start relying on the simpler C++11 semantics as you migrate a code base from C++98 to C++11 and may still have to support C++98 clients for a while.

In C++, is it still bad practice to return a vector from a function?

Short version: It's common to return large objects—such as vectors/arrays—in many programming languages. Is this style now acceptable in C++0x if the class has a move constructor, or do C++ programmers consider it weird/ugly/abomination?

Long version: In C++0x is this still considered bad form?

std::vector<std::string> BuildLargeVector();

...

std::vector<std::string> v = BuildLargeVector();

 

[...]

Quick Q: C++ template typedef -- StackOverflow

In the "look how simple this is now in C++11" department, this just in on SO:

C++ template typedef

I have a class

template<size_t N, size_t M>

class Matrix {

    // ....

};

I want to make a typedef which creates a Vector (column vector) which is equivalent to a Matrix with sizes N and 1. Something like that:

typedef Matrix<N,1> Vector<N>;

Which produces compile error. The following creates something similar, but not exactly what I want:

template <int N>

class Vector: public Matrix<N,1>

{ };

Is there a solution or a not too expensive workaround / best-practice for it? Thanks in advance!

Quick Q: Does the range-based for loop make std algorithms obsolete? -- StackOverflow

Here's a fine question from StackOverflow[C++11]. Click through for some fine answers.

Does the Range-based for Loop Make std Algorithms Obsolete?

Algorithm solution:

std::generate(numbers.begin(), numbers.end(), rand);

Range-based for-loop solution:

for (int& x : numbers) x = rand();

Why would I want to use the more verbose std::generate over range-based for-loops in C++11?

Continue reading...

 

Stroustrup's Tour of C++: Third chapter posted

Part 3 of Bjarne Stroustrup's draft Tour of C++ is now available. This material is a preview draft of Chapter 4 of Stroustrup's upcoming The C++ Programming Language, 4th Edition.

A Tour of C++, Part 3: Containers and Algorithms

by Bjarne Stroustrup

Stroustrup writes:

No significant program is written in just a bare programming language,
it would be too tedious.

However, just about any task can be rendered simple by the use of good libraries.

This third chapter of my tour of C++ begins the presentation of the standard library, which is about half of the C++ standard.

Constructive comments would be most welcome.

C++ and Beyond 2012: Panel - Convincing your Colleagues

A new C++ and Beyond 2012 panel is now available:

C++ and Beyond 2012: Panel - Convincing your Colleagues

From C++ and Beyond 2012, Andrei, Herb and Scott present Convincing Your Colleagues - an interactive panel.

Abstract:

You can't do a better job if you don't change what you're doing, but change is hard.  It's especially hard when what needs to change is your colleagues' approach to software development. Moving your team forward often requires persuading your peers to change their behavior, sometimes to do something they're not doing, other times to stop doing something they've become accustomed to.  Whether the issue is to embrace or avoid C++ language features, to adopt new development tools or abandon old ones, to increase use of or scale back on overuse of design patterns, to adhere to coding standards, or any of the plethora of other matters that affect software creation, moving things forward typically requires getting your colleagues to buy into the change you're proposing.  But how can you do that?

In this panel session, Andrei, Herb, and Scott share how they go about convincing their colleagues to change and take questions from the audience.