Relative Content

Tag Archive for c++11

Move semantics in C++ – Move-return of local variables

My understanding is that in C++11, when you return a local variable from a function by value, the compiler is allowed to treat that variable as an r-value reference and ‘move’ it out of the function to return it (if RVO/NRVO doesn’t happen instead, of course).

Who is to blame for this range based for over a reference to temporary?

The following code looks rather harmless on first sight. A user uses the function bar() to interact with some library functionality. (This may have even worked for a long time since bar() returned a reference to a non-temporary value or similar.) Now however it is simply returning a new instance of B. B again has a function a() that returns a reference to an object of the iterateable type A. The user wants to query this object which leads to a segfault since the temporary B object returned by bar() is destroyed before the iteration begins.

Who is to blame for this range based for over a reference to temporary?

The following code looks rather harmless on first sight. A user uses the function bar() to interact with some library functionality. (This may have even worked for a long time since bar() returned a reference to a non-temporary value or similar.) Now however it is simply returning a new instance of B. B again has a function a() that returns a reference to an object of the iterateable type A. The user wants to query this object which leads to a segfault since the temporary B object returned by bar() is destroyed before the iteration begins.

Too many parameters to data processing class constructor

I have a conceptually simple application: data comes in as small encrypted packets, they decrypted and validated, some are stored in the database, some rules are applied, and a reply might be encrypted and sent. Packets arrive at a rate of high hundreds of thousands per thread per second, so performance is a consideration. I am leaving out most of the performance elements here to focus on the design.

Why lambda/closures expressions came so late to C++?

I was reading a really great Bjarne Stroustrup’s article where he exposes some C++ myths.
I look at code that focus my attention, because I wouldn’t know that C++ supports this kind of expressions. I’m talking about lambda expressions, or closures.

Why lambda/closures expressions came so late to C++?

I was reading a really great Bjarne Stroustrup’s article where he exposes some C++ myths.
I look at code that focus my attention, because I wouldn’t know that C++ supports this kind of expressions. I’m talking about lambda expressions, or closures.