basics

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.

C++ and Xcode 4.6 -- from Marshall Clow

Marshall Clow gives some helpful tips for C++ programmers migrating to to XCode 4.6:

C++ and XCode 4.6

So, you’ve installed Xcode 4.6, and you are a C++ programmer.

You want to use the latest and greatest, so you create a new project, and add your sources to the project, and hit Build, and … guess what? Your code doesn’t build!

Continue reading...

 

Image Watch: C++ image and video debugging plug-in for VS 2012

We continue to see modern C++ tool development across the industry continue apace. Here's another new cool C++-oriented tool with a nice seven-minute video on Channel 9:

Introducing Image Watch - A VS 2012 Plug-In for C++ Image and Video Debugging

Image Watch is a new Visual Studio 2012 plug-in for debugging C++ image and video processing applications, for example photo or augmented reality apps. Image Watch provides a watch window that can display in-memory bitmaps during debugging, so you no longer need to litter your code with "save-this-intermediate-image-to-a-file" statements when tracking down bugs. The initial release has built-in support for OpenCV image types and can be extended for viewing user-defined image types as well.

Here, Wolf Kienzle, Senior Research Developer, Interactive Visual Media group, Microsoft Research Redmond, explains and demos this excellent new tool for C++ developers building image, video or augmented reality apps. In effect, you can step into pixels...

No, really, moving a return value is easy -- StackOverflow

People new to C++11 often hear about move semantics, and expect that they have to do work to take advantage of it. That's often not true, and often the cleanest, simplest code that doesn't even mention move or && anywhere is just what you want -- that's C++11, clean, safe, and faster than ever.

Perhaps the most common case (and question) involves returning values from functions. The new rule for modern C++ style: Just return even big objects by value, and move Just Happens.

It just came up again on StackOverflow:

C++11 rvalues and move semantics confusion

The link skips straight to Howard Hinnant's clear and correct answer.

Sometimes we just try too hard, because we expect efficient programming not to be easy. Welcome to C++11.

Quick Q: How do I move an expensive object into a map? -- StackOverflow

Quick A: Using the form of insert that takes an rvalue and passing a temporary or a std::move'd object, or calling emplace.

Moving an object into a map

The problem with this is that the huge objects will be copied into the maps

 

Huge huge1(some,args);
Huge huge2(some,args);

std::map<int,Huge> map1;
std::map<Huge,int> map2;

map1.insert({0,huge1});
map2.insert({huge2,0});

how can I guarantee a move? Will this work or is there more to it?

map1.insert({0,std::move(huge1)});
map2.insert({std::move(huge2),0});