basics

Quick Q: Why might a C++11 range-for loop appear slow? -- StackOverflow

Quick, can you spot the problem in this line of code?

for(vector<int> vec1 : backgroundData)

Probably you can -- but what's the best solution?

Read on here, yesterday on StackOverflow:

C++11: Why does this range loop decrease FPS by 35?

[...] Is the C++11 range-based loop so much slower than the old school for? I really want to hear an answer to this, because my eyes honestly prefer the range based loop, and I'd hate to find out that the range based loop is twice as slow.

 

Ten C++11 Features Every C++ Developer Should Use -- Marius Bancila

codeproject.pngIgnoring the dangers of linking to items published on April 1, we offer:

Ten C++11 Features Every C++ Developer Should Use

by Marius Bancila

This article discusses a series of features new to C++11 that all developers should learn and use. There are lots of new additions to the language and the standard library, and this article barely scratches the surface. However, I believe some of these new features should become routine for all C++ developers. You could probably find many similar articles evangelizing different C++11 features. This is my attempt to assemble a list of C++ features that should be a norm nowadays. Table of contents:

  • auto
  • nullptr
  • Range-based for loops
  • Override and final
  • Strongly-typed enums
  • Smart pointers
  • Lambdas
  • non-member begin() and end()
  • static_assert and type traits
  • Move semantics

Quick Q: How should you use the standard smart pointers as members? -- StackOverflow

From StackOverflow:

Using smart pointers for class members

I'm having trouble understanding the usage of smart pointers as class members in C++11. I have read a lot about smart pointers and I think I do understand how unique_ptr and shared_ptr/weak_ptr work in general. What I don't understand is the real usage. It seems like everybody recommends using unique_ptr as the way to go almost all the time. But how would I implement something like this: ...

Webinar: C++ in the Multi-Device Enterprise -- David Intersimone

On Tuesday, March 26, Embarcadero's David Intersimone will be speaking live on the web:

C++ in the Multi-Device Enterprise

David Intersimone, "David I"
Vice President of Developer Relations and Chief Evangelist

Tuesday, March 26, 2013

  • 6:00AM PDT / 9:00AM EDT / 13:00 UTC
  • 11:00AM PDT / 2:00PM EDT / 18:00 UTC
  • 5:00PM PDT / 8:00PM EDT / 11:00AM 27-Mar Australia EDT

Description:

In every conversation, social network post and industry article, you hear about the need for multi-device support inside an Enterprise.  Terms like BYOD appear in most articles and Enterprise strategies.  Computing in a modern Enterprise is not only a Microsoft Windows world.  Enterprise organizations need to support a wide array of devices that their employees are using to be more productive.  The modern enterprise also needs to support additional software architectures including Cloud computing, multi-tier, REST and SOAP web services and more.

This webinar showcases how C++ can help satisfy the Enterprise’s need to support multiple devices on desktops, servers, web, mobile and multi-tiers in their infrastructure.  Coverage includes C++Builder’s support for ISV and enterprise class integrated database, middleware and cloud computing. With C++Builder XE3, you get integrated support for SQL Server, Oracle, Sybase, DB2, InterBase, SQL Anywhere, SQLite, MySQL, and cloud services including Windows Azure and Amazon.

During the webinar, you will learn how to:

  • Leverage platform services, devices and sensors in your multi-device C++ applications
  • Build multi-device C++ applications that connect with enterprise SQL databases
  • Create multi-device C++ desktop applications that consume web services using SOAP and REST
  • Build scalable multi-tier, multi-device, master detail database applications

Quick Q: Why use C varargs when you have initializer_lists and variadic templates? -- StackOverflow

Quick A: No reason, varargs are type-unsafe and entirely superseded by C++11 features (unless you need C compatibility).

Why use variadic arguments now when initializer lists are available?

I've been wondering what are the advantages of variadic arguments over initializer lists. Both offer the same ability -- to pass indefinite number of arguments to a function.

 

What I personally think is initializer lists are a little more elegant. Syntax is less awkward.

Also, it appears that initializer lists have significantly better performance as the number of arguments grows.

 

So what am I missing, besides the possibility to use use variadic arguments in C as well?

Meeting C++ 2013 -- Nov 8-9, Düsseldorf, Germany

As C++ heats up, we continue to see new conferences including this one that launched last year. Europe's newest C++ conference is being held again in 2013, with room for 250 attendees and several standards committee members already signed up to speak:

Meeting C++ 2013 Announcement

Information page

Call for Papers (open until May 15)

After last years great success, we will meet again for 2 days full of C++ in Germany this Fall. Meeting C++ 2013 will be again at the 2nd weekend of November (8./9.11.2013). This time the conference will take place at the Lindner Congresshotel in Düsseldorf. For this year there will be 25 Talks and up to 2 keynotes for the 250 attendees at the conference! ...

There will be 3 Tracks about C++ this year, with the 3rd track being a theme track about C++ and UI. ... The other two tracks will offer general C++ talks like last year.

What's the difference between push_back vs emplace_back? -- StackOverflow

Quick A: When correctly implemented per the standard, you get in-place construction with perfect forwarding.

Longer question:

push_back vs emplace_back

I'm a bit confused regarding the difference between push_back and emplace_back.

 

void emplace_back(Type&& _Val);
void push_back(const Type& _Val);
void push_back(Type&& _Val);

As there is a push_back overload taking a rvalue reference I don't quite see what the purpose of emplace_back becomes?

Quick Q: Why isn't std::initializer_list a core-language built-in? -- StackOverflow

Quick A: Because it doesn't have to be. It's "the C++ way" to prefer library solutions, and initializer_list shows how far you can get with a pure library solution, then the rest of the way with minimal language support to create initializer_list objects.

Recently on SO:

Why isn't std::initializer_list a core-language built-in?

It seems to me that it's quite an important feature of C++11 and yet it doesn't have its own reserved keyword (or something alike).

 

Instead, initializer_list it's just a template class from the standard library that has a special, implicit mapping from the new braced-init-list {...} syntax that's handled by the compiler.

At first thought, this solution is quite hacky. ...

Quick Q: How to initialize a const object (say vector) with complex initialization? -- StackOverflow

Quick A: With a lambda function. Try const mytype myobj{ []{ /* compute value */ return value; } }.

How would you initialize a const vector of function results using C++11?

Is it possible to use something like generate_n to create a const vector of, say, random numbers? I couldn't think of a way to do it without deriving vector and doing the assignment in the constructor.