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

 

Where is C++ used, besides everywhere? -- David Intersimone

From David I's blog at Embarcadero, a nice summary of where C++ is used with links to more... the next best thing to a "C++ inside" logo.

Multi-Device C++ is used everywhere on planet Earth and beyond!

In my conversation with Bjarne Stroustrup during the CodeRage 7 C++ Conference (replays of the sessions are available to watch and download) last December, Bjarne talked about how pervasive C++ is in enterprises, infrastructures, major application software and operating platforms. C++ is used to build Operating Systems, Libraries, Applications and Scalable Systems.  C++ is used in many different markets on planet Earth and beyond...

 

Image Watch: C++ image and video debugging plug-in for VS 2012

We continue to see modern C++ tool development across the industry continue apace. Here's another new cool C++-oriented tool with a nice seven-minute video on Channel 9:

Introducing Image Watch - A VS 2012 Plug-In for C++ Image and Video Debugging

Image Watch is a new Visual Studio 2012 plug-in for debugging C++ image and video processing applications, for example photo or augmented reality apps. Image Watch provides a watch window that can display in-memory bitmaps during debugging, so you no longer need to litter your code with "save-this-intermediate-image-to-a-file" statements when tracking down bugs. The initial release has built-in support for OpenCV image types and can be extended for viewing user-defined image types as well.

Here, Wolf Kienzle, Senior Research Developer, Interactive Visual Media group, Microsoft Research Redmond, explains and demos this excellent new tool for C++ developers building image, video or augmented reality apps. In effect, you can step into pixels...

Microsoft releases C++ REST SDK ("Casablanca")

From the announcement:

The C++ REST SDK (codename "Casablanca") has officially been released as an open source project on CodePlex...

We first announced Casablanca as an incubation project on Microsoft's DevLabs back in April of 2012. Since then we have had several releases and have seen library quickly evolve. As we added new features and received feedback from customers, it was evident that two separate entities were beginning to form. As a result, the "Casablanca" project on DevLabs has been separated into 2 different SDKs: the C++ REST SDK and the Azure SDK for C++.

The first of the two SDKs being released is the C++ REST SDK. It includes tools to quickly write modern, asynchronous C++ code that connects with REST services. We take advantage of the power and productivity offered in C++11 while providing a cross-platform solution. We currently support Windows 7, Windows 8 (Windows store and desktop applications), and Linux.

The main features in this SDK include:

  • Ability to create a connection to a server via a HTTP Client, send requests and handle response.
  • Support for construction and use of Uniform Resource Identifiers (URI).
  • Constructing, parsing and serializing JSON values.
  • Asynchronously reading/writing bytes to/from an underlying medium via Streams and Stream Buffers.

Continue reading...