April 2013

New paper: N3631, C11: The New C Standard -- Tom Plum

Note: Both this paper by Tom Plum and the other just posted by Bjarne Stroustrup refer to prior published articles about C and C++ compatibility. The reason for drawing attention to that information is that C and C++ compatibility is now expected to be discussed at next week's ISO C++ meeting in Bristol. For an example why this discussion is taking place now, see paper N3557 section 7, which raises the question of compatibility between C and C++ for parallelism, including that pressure from C choices affects our design choices for C++ as well.

However, the C++ committee's focus at Bristol is still on working toward a Committee Draft ballot for C++14. This C/C++ compatibility discussion is expected to take place late in the meeting when the technical work for C++ in general and C++14 in particular is complete.

 

A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N3631

Date: 2013-04-09

C11: The New C Standard

by Tom Plum

Excerpt, including explaining why the above title is not a link:

This material was originally published in a series of articles in Dr. Dobb’s (www.drdobbs.com) and is reprinted here, with permission, for use by C++ committee members. Outside the committee, please refer to readers to the following links, rather than distributing this document. (Copyright 2012 Dr. Dobb’s)

http://www.drdobbs.com/cpp/232800444 (C11 overview, concurrency, etc.)

http://www.drdobbs.com/cpp/232901670 (C11 security, Annex K, Annex L)

http://www.drdobbs.com/cpp/240001401 (Alignment, Unicode, ease‐of‐use features, C++ compatibility)

New paper: N3628, C and C++ Compatibility -- Bjarne Stroustrup

A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N3628

Date: 2013-04-08

C and C++ Compatibility

by Bjarne Stroustrup

Excerpt:

It seems that a serious discussion about C/C++ compatibility is starting. “By popular demand,” here is a paper in three parts that I wrote just over 10 years ago. Much have changed since that, so please don’t expect the paper to be completely up-to-date or to completely reflect my current views. However, I don’t have the time to write a 2013 version of these 2002 papers, and I don’t change my fundamental opinions all that often. I think that C/C++ compatibility is very important and valuable for both the C and C++ communities.

  • C and C++: Siblings. The C/C++ Users Journal. July 2002.
  • C and C++: A Case for Compatibility. The C/C++ Users Journal. August 2002.
  • C and C++: Case Studies in Compatibility. The C/C++ Users Journal. September 2002.

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.

 

Universal References (revisited) -- Ben Hekster

A response to Scott Meyers' recent article on Universal References, showing an analogy between &&-collapsing and const-collapsing, and making the counterargument that inventing a new concept may not be needed to clearly explain the standard. It's always interesting to see different experts' takes on how to understand and teach a  feature, particularly a new C++11 feature that we as a community are still absorbing.

Universal References

by Ben Hekster

... The ‘universal reference’ is not a concept you will see defined in the C++ standard, nor is it even something that has any conceptually objective existence in the language or compilation process. It is a construct defined by Meyers in an attempt to make some sense of behavior in the language that he presents as being unexpected or even mysterious. On closer inspection, however, I find that the observed mysterious behavior is actually quite readily explained and has an existing analog that corresponds to already intuitively-understood behavior. ...

Complex Initialization for a Const Variable -- Herb Sutter

How do you declare a const int variable when you have still have to do some computation to initialize it (so it shouldn't be const at first) but then want it be const after that?

Complex Initialization for a Const Variable

by Herb Sutter

 

On std-discussion, Shakti Misra asked:

> I have seen in a lot of places code like

int i;
if(someConditionIstrue)
{
    Do some operations and calculate the value of i;
    i = some calculated value;
}
use i; //Note this value is only used not changed. It should not be changed.

 

Olaf nailed it: The way to do it is with a lambda. ...

A Look at C++14 and Beyond: Papers Part 3 -- Meeting C++

And part 3:

A look at C++14 and beyond: Papers Part 3

This is the 3rd part of my little series over the papers in the Pre-Bristol mailing. I have added "and beyond" to the title, as I decided to handle all papers with Part 2, and now will continue to do so. This edition will again feature a few highlights, and a lot of proposals from different areas of C++.

Also, please understand, that all of the papers here are proposals. None of them are voted into any standard yet, maybe Bristol will give us a hint about what to expect for C++14, maybe not. Still, the proposals will give an impression, on what C++14 could be like.

A Look at C++14: Papers Part 2 -- Meeting C++

A few days ago, we linked to Part 1. As noted there, although the article is labeled “A look at C++14,” not all of these papers are for C++14, and regardless of timeframe not all will be adopted. But it is a useful look at what’s on the commitee’s radar.

Part 2 has just been posted:

A look at C++14: Papers Part 2

This is the second part of my C++ Standardization Papers series. The first part has been received quite well, with more then 5k views in the first two days. Also isocpp.org, Phoronix, lwn.net, a lot of russian blogs and others have linked to it. There also was a nice discussion on reddit. Again, like in Part 1, I want to emphasize, that I only cover part of all papers in this blog post. Also not all of these papers are meant to be happening with C++14, modules & concepts for example are not going to be part of C++14 (at least this is highly unlikely). Still, I will cover those papers too, as some of them will be discussed in Bristol for sure. All papers can be found here.

Some words on C++14. C++14 is not going to be like C++11 changing the language a lot. Its more meant to enhance the language with libraries, and improve or provide bug fixes for C++11. That's why you could call C++14 a minor Standard, and the next major C++ Standard is C++17, at least you could see this as the current plan and road map for C++. But lets have a look at the papers: ...

 

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