New paper: N3531, User-defined Literals for Standard Library Types -- Peter Sommerlad

A new WG21 paper is available. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N3531

Date: 2013-03-08

User-defined Literals for Standard Library Types (version 3)

by Peter Sommerlad

Excerpt:

The standard library is lacking pre-de fined user-defi ned literals, even though the standard reserves names not starting with an underscore for it. Even the sequence of papers that introduced UDL to the standard contained useful examples of suffixes for creating values of standard types such as s for std::string, h for std::chrono::hours and i for imaginary parts of complex numbers.

Discussion on the reflector in May 2012 and in Portland Oct 2012 showed demand for some or even many pre-de fined UDL operators in the standard library...

New page: Papers and Mailings

There's a new page under Standardization -> Meetings and Participation that answers common questions about "what are papers and mailings all about?"

Papers and Mailings

This is timely information, because the pre-meeting mailing deadline is just a week away -- next Friday, March 15.

We'll continue to expand this and other standardization information to answer frequently asked questions and keep it current.

 

New paper: N3536, C++ Sized Deallocation -- Lawrence Crowl

A new WG21 paper is available:

Document number: N3536

Date: 2013-03-05

C++ Sized Deallocation

by Lawrence Crowl

 

Excerpt:

Problem

With C++11, programmers may define a static member function operator delete that takes a size parameter indicating the size of the object to be deleted. The equivalent global operator delete is not available. This omission has unfortunate performance consequences.

Modern memory allocators often allocate in size categories, and, for space efficiency reasons, do not store the size of the object near the object. Deallocation then requires searching for the size category store that contains the object. This search can be expensive, particularly as the search data structures are often not in memory caches.

Solution

Permit implementations and programmers to define sized versions of the global operator delete. The compiler shall call the sized version in preference to the unsized version when the sized version is available.
...

New paper: N3526, Uniform initialization for arrays and class aggregate types -- Michael Price

A new WG21 paper is available:

Document number: N3526

Date: 2013-01-21

Uniform initialization for arrays and class aggregate types

 

by Michael Price

An excerpt:

This document proposes a slight relaxation of the rules for eliding braces from aggregate initialization in order to make initialization of arrays and class aggregates more uniform. This change is required in order to support class aggregate types with a single member subaggregate that behave similarly to their array counterparts (i.e. std::array).

[...]

However, when we begin to mix the aggregate types, uniform initialization begins to break down.

  struct aggr_t {
      int a;
      int b;
  }  array_of_aggr[2] = {{1, 2}, {3, 4}};

  struct aggr_ex_t {
      int x[2][2];
  };

  aggr_ex_t bad  = {{1, 2}, {3, 4}};      // Error: Too many initializers, see below for details
  aggr_ex_t good = {{{1, 2}, {3, 4}}};

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. ...

The Importance of std::function -- Malte Skarupke

See also "Generalizing Observer", written ten years ago when std::function was first adopted.

The Importance of std::function

by Malte Skarupke

... Classically an update loop would be implemented something like this: ...

And this is a good solution at first. But you’ve got that inheritance in there, and that doesn’t scale. You will probably want to add a render loop and maybe a separate update loop for the editor. Once you’ve got that many base classes it makes sense to combine them into one. And now you’ve just started on the way of having a big base class that gets used everywhere. Soon enough adding something different to the update loop involves a whole lot of unnecessary work.

Here is an alternate update loop using std::function: ...

 

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.

Registration open for C++ and Beyond 2013

This just in on the C++ and Beyond blog... Scott Meyers writes:

Registration for C&B 2013 is open!

C++ and Beyond 2013 will take place December 9-12 at the Salish Lodge and Spa in Snoqualmie, Washington, USA (not far from Seattle). Registration is now open.

Attendance will be limited to 64 people.  (That’s the capacity of the ballroom.) Given that C&B has attracted about 100 people each year, it’s essentially certain that we’ll sell out.  As a result, I encourage you to sign up as soon as you can. Once we sell out, we’ll start a waiting list, but past experience suggests that we won’t be able to offer spots to more than a handful of people on that list.

Early bird registration runs through June 9 and features a 10% discount off the standard registration fee.

Click here to register.

Detailed information about C++ and Beyond is available at its web site:

Andrei and Herb and I hope to see you at C&B 2013 in December!

Scott

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...