August 2013

New paper: N3740, A Proposal for the World’s Dumbest Smart Pointer, v2 -- Walter Brown

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

Date: 2013-08-30

A Proposal for the World’s Dumbest Smart Pointer, v2

by Walter Brown

Excerpt:

We present the following code as a preliminary specification of intent in order to serve as a
basis for technical discussion. Designed as a pointer that takes no formal notice of its pointee’s
lifetime, this not-very-smart pointer template is intended as a replacement for near-trivial uses of
bare/native/raw/built-in/dumb C++ pointers, especially when used to communicate with (say)
legacy code that traffics in such pointers. It is, by design, exempt (hence its working name) from
any role in managing any pointee, and is thus freely copyable independent of and without regard
for its pointee.

We have found that such a template provides us a standard vocabulary to denote non-owning
pointers, with no need for further comment or other documentation to describe the near-vacuous
semantics involved...

Quick Q: How is std::function implemented? -- StackOverflow

Quick A: Using type erasure.

Quick Q2: ... Um, what's that?

Quick A2: Read this post...

How is std::function implemented?

According to the sources I have found, a lambda expression is essentially implemented by the compiler creating a class with overloaded function call operator and the referenced variables as members. This suggests that the size of lambda expressions varies, and given enough references variables that size can be arbitrarily large.

An std::function should have a fixed size, but it must be able to wrap any kind of callables, including any lambdas of the same kind. How is it implemented? If std::function internally uses a pointer to its target, then what happens, when the std::function instance is copied or moved? Are there any heap allocations involved?

New paper: N3711, Task Groups As a Lower Level C++ Library Solution To Fork-... -- Laksberg, Sutter

N3711.pdfA 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: N3711

Date: 2013-08-15

Task Groups As a Lower Level C++ Library Solution To Fork-Join Parallelism

by Artur Laksberg and Herb Sutter

Excerpt:

The task_group concept proposed in this document is based on the common subset of the PPL and the TBB libraries, which also use task_group internally to implement many of their own parallel algorithms. This proposal complements the high-level Parallel STL algorithms proposal [2] by enabling arbitrary fork-join parallelism, including arbitrary additional higher-level parallelism algorithms, to be built in a natural and portable way.

Together with [2], we believe this offers a viable alternative to a language-based proposal for low-level fork-joined parallelism with competitive (or in some cases better) usability, generality, and performance.

New paper: N3716, A printf-like Interface for the Streams Library (revision 1) -- Zhihao Yuan

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

Date: 2013-08-18

A printf-like Interface for the Streams Library (revision 1)

by Zhihao Yuan

Excerpt:

Changes since N3506

  • Support Boost.Format’s simple positional syntax (%1%, %2% ...).
  • Cover the cornor cases “not-mentioned” by the C standard.
  • Mention the function style syntax suggested by BSI in “Future Issues”.

Overview

cout << putf("hello, %s\n", "world");

Printf defines the most widely used syntax to format a text output. It exists in C, Perl, Python and even Java™, and is available from Qt to Boost.Format[1], but not C++ standard library. This proposal tries to define such an interface based on the printf function defined by C[2] for the C++ I/O streams library, with the error handling policy and the type safety considered.

New paper: N3708, A proposal to add coroutines to the C++ standard library -- O Kowalke, N Goodspeed

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

Date: 2013-03-04

A proposal to add coroutines to the C++ standard library

by Oliver Kowalke and Nat Goodspeed

Excerpt:

This proposal suggests adding two first-class continuations to the C++ standard library:
std::coroutine<T>::pull_type and std::coroutine<T>::push_type.

A Glimpse into C++14: Combine Flexibility and Performance with Dynamic Arrays and... -- Danny Kalev

cpp14-target.jpgDanny Kalev wrote a nice article yesterday about a new C++ feature -- actually, two related C++14 features -- that were just added to the draft Standard in April and will be coming to real compilers in the near future.

A Glimpse into C++14: Combine Flexibility and Performance with Dynamic Arrays and Runtime-Sized Arrays

by Danny Kalev

From the article:

C99 introduced the notion of variable length arrays: stack allocated built-in arrays whose size is determined at runtime. C++ lacks a similar feature, to the discontent of many a programmer. However, two recent proposals for adding dynamic arrays and runtime-sized arrays to C++14 are closing the gap at last. Learn how to use these new features to imitate C99’s variable length arrays in C++...

New paper: N3733, ISO/IEC CD 14882, C++ 2014, National Body Comments -- Barry Hedquist

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

Date: 2013-08-26

ISO/IEC CD 14882, C++ 2014, National Body Comments

by Barry Hedquist, INCITS/PL22.16 IR

Excerpt:

Attached is a complete set of National Body Comments submitted to JTC1 SC22 in response to the SC22 Ballot for ISO/IEC CD 14882, Committee Draft of the revision of ISO/IEC 14882:2011, aka C++ 2014.

This document is a revision to SC22 N4836, CD14882 Collated Comments. The revision contains a consistent numbering scheme for all comments. Comments that contained no numbering were numbered sequentially in the exact order presented in SC22 N4836. Comments that were numbered in the "Line Number" column (column 2) were moved to the MB/NC column (column 1). No other editing was done on any of the comments.

Document numbers referenced in the ballot comments are WG21 documents unless otherwise stated.

Optimizing C++ Code: Dead Code Elimination -- Jim Hogg

We keep hearing about C++'s "as if" rule, but what does it really do? Fundamentally, it enables optimizations. A modern compiler never produces an executable that's identical to the program you actually wrote; it produces an equivalent program that's probably a lot better.

Hence Jim Hogg's nice new series on what optimizing compilers do, using Visual C++ as an example. The latest instalment:

Optimizing C++ Code : Dead Code Elimination

by Jim Hogg

From the article:

This post examines the optimization called Dead-Code-Elimination, which I’ll abbreviate to DCE.  It does what it says: discards any calculations whose results are not actually used by the program.

Now, you will probably assert that your code calculates only results that are used, and never any results that are not used: only an idiot, after all, would gratuitously add useless code -- calculating the first 1000 digits of pi, for example, whilst also doing something useful.  So when would the DCE optimization ever have an effect? ...