March 2013

DDS Programming Using Modern C++ -- Sumant Tambe

For those in the Bay area this week, the ACCU USA Chapter is presenting the following talk:

DDS Programming using Modern C++

Speaker: Sumant Tambe

Date: March 13, 2013

Location: Symantec, VCAFE building, 350 Ellis Street (near E. Middlefield Road), Mountain View, CA USA 94043

Sumant writes:

Resurgence of C++ is spreading in many industries. International computer system standards that target C++ for application portability, are quickly adopting modern C++. At the Object Management Group (OMG) -- an international standards consortium -- the DDS-PSM-Cxx and the IDL2C++11 standards have been ahead of the curve. The DDS-PSM-Cxx is among the family of standards around the core Data Distribution Service (DDS) standard for developing high-performance distributed real-time systems. ...

I’m privileged to talk about the DDS-PSM-Cxx standard in a local event organized by the San Francisco Bay Area Association of C/C++ Users (ACCU). This is a great after-hours free-of-cost get-together for anyone who wants to know more about C++. The event will take place on March 13th in Mountain View not far from the RTI HQ.

C++ to JavaScript with Emscripten

Want to run your C++ code in a browser? Check out this project that converts LLVM bitcode to JavaScript™. From the project homepage:

Emscripten is an LLVM to JavaScript™ compiler. It takes LLVM bitcode (which can be generated from C/C++ using Clang, or any other language that can be converted into LLVM bitcode) and compiles that into JavaScript™, which can be run on the web (or anywhere else JavaScript™ can run).

Using Emscripten, you can

  • Compile C and C++ code into JavaScript™ and run that on the web
  • Run code in languages like Python as well, by compiling CPython from C to JavaScript™ and interpreting code in that on the web

They even have Qt demos running!

Continue reading...

What new capabilities do user-defined literals add to C++? -- StackOverflow

Over the past year, UDLs have started to become available in some popular C++ compilers, including gcc 4.7 and Clang 3.1. As people are adopting those compilers in real code and starting to be ablel to use this feature, a natural question is how useful they are and how to use them:

What new capabilities do user-defined literals add to C++?

C++11 introduces user-defined literals which will allow the introduction of new literal syntax based on existing literals (int, hex, string, float) so that any type will be able to have a literal presentation.

Examples:

// imaginary numbers
std::complex<long double> operator "" _i(long double d) // cooked form
{
    return std::complex<long double>(0, d);
}
auto val = 3.14_i; // val = complex<long double>(0, 3.14)

// binary values
int operator "" _B(const char*); // raw form
int answer = 101010_B; // answer = 42

// std::string
std::string operator "" _s(const char* str, size_t /*length*/)
{
    return std::string(str);
}
auto hi = "hello"_s + " world"; // + works, "hello"_s is a string not a pointer

// units
assert(1_kg == 2.2_lb); // give or take 0.00462262 pounds

At first glance this looks very cool but I'm wondering how applicable it really is, [...] do you feel this feature will justify itself? What other literals would you like to define that will make your C++ code more readable?

New paper: N3538, Pass by Const Reference or Value -- Lawrence Crowl

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: N3538

Date: 2013-03-06

Pass by Const Reference or Value

by Lawrence Crowl

Excerpt:

Efficiency and expressiveness are hallmarks of C++, but sometimes those hallmarks conflict in ways that force programmers to compromise on one or the other. The progammer's choice of passing a given argument by const reference or by value is one of those compromises. That compromise has become more of a problem with modern calling conventions.

In this paper, we describe the problem, discuss possible approaches to reduce the problem, and explore a solution that introduces a new language feature...

New paper: N3535, C++ Stream Mutexes -- Lawrence Crowl

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: N3535

Date: 2013-03-06

C++ Stream Mutexes

by Lawrence Crowl

Excerpt:

At present, stream output operations guarantee that they will not produce race conditions, but do not guarantee that the effect will be sensible. Some form of external synchronization is required. Unfortunately, without a standard mechanism for synchronizing, independently developed software will be unable to synchronize.

 

This paper proposes a standard mechanism for locking streams...

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