basics

Quick Q: Does [=] capture all variables in scope? -- StackOverflow

Quick A: No.

A simple but important question:

C++11 lambda capture semantics

When I use [=] to indicate that I would like all local variables to be captured by value in a lambda, will that result in all local variables in the function being copied, or just all local variables that are used by the lambda?

So, for example, if I have:

vector<int> my_huge_vector(100000);
int my_measly_int;
some_function([=](int i){ return my_measly_int + i; });

Will my_huge_vector be copied, even though I don't use it in the lambda?

Quick Q: static constexpr variable vs. constexpr function? -- StackOverflow

With a nice Quick A by Morwenn that not only gives the right answer as of today, but is current with a feature voted into C++14 just two weeks ago that lets you drop the ()'s:

static constexpr variable vs. function

Is there a difference between declaring floating point constant as a static constexpr variable and a function as in example below, or is it just a matter of style?

class MY_PI
{
public:
    static constexpr float MY_PI_VAR = 3.14f;
    static constexpr float MY_PI_FUN() { return 3.14f; }
}

Quick Q: When should I use noexcept? -- StackOverflow

As C++11-compliant compilers start to roll out and be adopted, people want to know to best use new C++11 features, such as:

When Should I Really Use noexcept?

 

  1. There are many examples of functions that I know will never throw, but for which the compiler cannot determine so on its own. Should I append noexcept to the function declaration in all such cases? ... For which situations should I be more careful about the use of noexcept, and for which situations can I get away with the implied noexcept(false)?
  2. When can I realistically except to observe a performance improvement after using noexcept... Do modern compilers take advantage of noexcept in this way? If not, can I excect some of them to do so in the near future?

 

Quick Q: What Is the Difference Between set and unordered_set in C++? -- StackOverflow

A common Q with a nice concise A:

What is the difference between set and unordered_set in C++?

Came across this good question, which is similar but not at all same since it talks about Java, which has different implementation of hash-tables, [...] So what is the difference in C++ implementation of set and unordered_set? This question can be ofcourse extended to map vs unordered_map and so on for other C++ containers.

Here is my initial assessment...

Quick Q: How Can Use a Lambda Function as a Hash Function for unordered_map? -- StackOverflow

Quick A: Name the lambda (by assigning it to a variable), then decltype it.

People sometimes ask this, so it's worth putting out a quick link to the short answer:

How to use lambda function as hash function in unordered_map?

I wonder if it is possible to use lambda function as custom hash function for unordered_map in C++11? If so, what is the syntax?

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