Copying Container Elements From The C++ Library: It's Trickier Than It Looks -- Andrew Koenig
Copying Container Elements From The C++ Library: It's Trickier Than It Looks
by Andrew Koenig
From the article:
Now consider this call:
v.push_back(v[0]);
October 25, Pavia, Italy
November 6-8, Berlin, Germany
November 3-8, Kona, HI, USA
By Blog Staff | May 31, 2013 02:41 PM | Tags: None
Copying Container Elements From The C++ Library: It's Trickier Than It Looks
by Andrew Koenig
From the article:
Now consider this call:
v.push_back(v[0]);
By seth | May 31, 2013 11:09 AM | Tags: None
The release of GCC 4.8.1 was announced today (31 May 2013) on the gcc mailing list. In addition to many bug fixes, GCC 4.8.1 adds support for C++11 ref-qualifiers, the final missing C++11 feature. This makes GCC the first C++11 [Ed.: language specification] feature complete compiler to be released.
Information on the full set of changes is available on the GCC 4.8 series page.
Clang 3.3, also C++11 feature complete, is in release testing and the release is currently scheduled for June 5th. Within a week full C++11 support will be available from two major compilers and on numerous platforms supported by those compilers.
Forging ahead with support for the next C++ standard.
By Blog Staff | May 30, 2013 02:36 PM | Tags: intermediate basics
The solution to GotW #89 is now available:
GotW #89 Solution: Smart Pointers (updated for C ++11/14)
by Herb Sutter
From the article:
So, why use
make_shared(or, if you need a custom allocator,allocate_shared) whenever you can, which is nearly always? There are two main reasons: simplicity, and efficiency...
By Blog Staff | May 29, 2013 03:59 PM | Tags: None
Here's a nice detailed treatment of auto and decltype by longtime author Thomas Becker.
C++ auto and decltype Explained
by Thomas Becker
From the article:
A while later, sometime in 2012, I noticed that there was another feature, or rather, a pair of features, in C++11 that I had not fully understood, namely, the
autoanddecltypekeywords. Withautoanddecltype, unlike rvalue references, the problem is not that they are difficult to grasp. On the contrary, the problem is that the idea is deceptively easy, yet there are hidden subtleties that can trip you up.Let's start with a good look at the
autokeyword...
By Blog Staff | May 29, 2013 10:22 AM | Tags: basics
New at the IBM DeveloperWorks C/C++ Cafe:
Defaulted functions in C++11
by Fang Lu
From the article:
The defaulted functions feature is newly introduced into the C++11 standard. In this article, I will explain this feature and provide some examples on how to use it.
By Blog Staff | May 29, 2013 09:32 AM | Tags: intermediate basics
The solution to GotW #6b is now available:
GotW #6b Solution: Const-Correctness, Part 2 (updated for C ++11/14)
by Herb Sutter
From the article:
Option 1 is to use a mutex in the perhaps-soon-to-be-canonical “
mutable mutex mutables” pattern:// Option 1: Use a mutex double get_area() const { auto lock = unique_lock<mutex>{mutables}; if( area < 0 ) // if not yet calculated and cached calc_area(); // calculate now return area; } private: // ... mutable mutex mutables; // canonical pattern: mutex that mutable double area; // covers all mutable membersOption 1 generalizes well if you add more data members in the future. However, it’s also more invasive and generalizes less well if you add more
Option 2 is to just changeconstmember functions in the future that usearea, because they will all have to remember to acquire a lock on the mutex before usingarea.doubletomutable atomic<double>. ...
By Blog Staff | May 28, 2013 03:06 AM | Tags: intermediate
Enquiring minds want to know: Why use unique_ptr<T[]> vs. vector<T> vs. array<T>?
Is there any use for unique_ptr with array?
std::unique_ptrhas support for arrays, for instance:
std::unique_ptr<int[]> p(new int[10]);but is it needed? probably it is more convenient to use
std::vectororstd::array.Do you find any use for that construct?
By Blog Staff | May 27, 2013 02:32 PM | Tags: None
As a considerable portion of the C++ world's writership and readership is taking holiday, a less technical thought:
Isn't there an interesting parallel between these two quotes taken from interviews with industry luminaries?
From an interview with Ed Catmull (President of Pixar):
The notion that you’re trying to control the process and prevent error screws things up. We all know the saying it’s better to ask for forgiveness than permission. And everyone knows that, but I think there is a corollary: if everyone is trying to prevent error, it screws things up. It’s better to fix problems than to prevent them. And the natural tendency for managers is to try and prevent error and over-plan things.
From an interview with Bjarne Stroustrup (creator of C++):
I do not consider it the job of a programming language to be “secure.” Security is a systems property and a language that is -- among other things -- a systems programming language cannot provide that by itself. C++ offers protection against errors, rather than protection against deliberate violation of rules. C++11 is better at that than C++98, but the repeated failures of languages that did promise security (e.g. Java), demonstrates that C++’s more modest promises are reasonable. Unfortunately, “we” have built an infrastructure with weak interfaces, poor hardware protection, and a maze of complex communication protocols that seriously complicates security, but that’s not for any individual language or even for all programming languages to solve. Trying to address security problems by having every programmer in every language insert the right run-time checks in the code is expensive and doomed to failure.
Hat tip to Daring Fireball.
By Blog Staff | May 24, 2013 05:48 PM | Tags: None
Stroustrup paper selected by Computing Reviews Best of 2012
"Software Development for Infrastructure" by Dr. Bjarne Stroustrup was selected as a notable paper in computing in 2012 by ACM's Computing Reviews Best of 2012. The Best of 2012 list consists of book and article nominations from CR's reviewers and category editors, the editors in chief of journals covered by CR, and others in the computing community. The paper was a cover feature article published in the IEEE Computer Society's January 2012 issue.
The basic premise of the paper is that "Infrastructure software needs more stringent correctness, reliability, efficiency, and maintainability requirements than non-essential applications. This implies greater emphasis on up-front design, static structure enforced by a type system, compact data structures, simplified code structure, and improved tool support. Education for infrastructure and application developers should differ to reflect that emphasis."
Dr. Stroustrup concludes that "In research, we need a greater appreciation of incremental (engineering) improvements with a relevance to real-world systems. 'That's just engineering, and we're computer scientists' is an attitude we can't afford. I suspect the era of transformative breakthroughs is over. We need to achieve a factor-of-two-or-three improvement in several areas, rather than trying to solve our problems with a single elusive two-orders-of-magnitude improvement from a silver bullet."
By Blog Staff | May 24, 2013 03:48 PM | Tags: None
The solution to GotW #6a is now available:
GotW #6a Solution: Const-Correctness, Part 1 (updated for C ++11/14)
by Herb Sutter
From the article:
Starting with C++11,
conston a variable that is possibly shared means read-only, safe to read concurrently without external synchronization.If you perform any operation on a
constshared variablex, or call a const member function onx, you can assume that operation does not change the observable value ofx-- or even modify the bits ofxin an observable way even in the presence of concurrency. ...Guideline: Remember the “M&M rule”: For a member variable,
mutableandmutex(oratomic) go together. ...