New adopted paper: N3642, User-defined Literals for Standard Library Types (pt1 v4) -- P. Sommerlad

Note: This paper was adopted into draft C++14 on Saturday at the Bristol UK ISO C++ meeting.

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

Date: 2013-04-18

User-defi ned Literals for Standard Library Types (part 1 - version 4)

by Peter Sommerlad

This allows code like the following:

auto mystring = "hello world"s;   // type std::string

auto mytime = 42ns;               // type chrono::nanoseconds

 

New adopted paper: N3654, Quoted Strings Library Proposal (Revision 2) -- Beman Dawes

Note: This paper was adopted into draft C++14 on Saturday at the Bristol UK ISO C++ meeting.

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

Date: 2013-04-19

Quoted Strings Library Proposal (Revision 2)

by Beman Dawes

Excerpt:

The proposed quoted stream I/O manipulator places delimiters, defaulted to double-quote ("), around strings on output, and strips off the delimiters on input. This ensures strings with embedded white space round-trip as desired. For example,

std::stringstream ss;
std::string original = "foolish me";
std::string round_trip;

ss << quoted(original);
ss >> quoted(round_trip);

std::cout << original;     // outputs: foolish me
std::cout << round_trip;   // outputs: foolish me

assert(original == round_trip); // assert will not fire

If the string contains the delimiter character, on output that character will be preceded by an escape character, default to backslash (\), as will the escape character itself:

std::cout << quoted("She said \"Hi!\"");  // outputs: "She said \"Hi!\""

 

New adopted paper: N3656, make_unique (Revision 1) -- Stephan T. Lavavej

Note: This paper was adopted into draft C++14 on Saturday at the Bristol UK ISO C++ meeting.

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: N3656.txt

Date: 2013-04-18

make_unique (Revision 1)

by Stephan T. Lavavej

The paper includes source code for a complete implementation.

New adopted paper: N3668, exchange() Utility Function, revision 3 -- Jeffrey Yasskin

Note: This paper was adopted into draft C++14 on Saturday at the Bristol UK ISO C++ meeting.

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

Date: 2013-04-19

exchange() utility function, revision 3

by Jeffrey Yasskin

Excerpt:

Atomic objects provide an atomic_exchange function ([atomics.types.operations.req]p18) that assigns a new value to the object and returns the old value. This operation is also useful on non-atomic objects, and this paper proposes adding it to the library. The benefit isn't huge, but neither is the specification cost.

template<typename T, typename U=T>
T exchange(T& obj, U&& new_val) {
  T old_val = std::move(obj);
  obj = std::forward<U>(new_val);
  return old_val;
}

For primitive types, this is equivalent to the obvious implementation, while for more complex types, this definition

  • Avoids copying the old value when that type defines a move constructor
  • Accepts any type as the new value, taking advantage of any converting assignment operator
  • Avoids copying the new value if it's a temporary or moved.

New adopted paper: N3649, Generic (Polymorphic) Lambda Expressions (R3) -- Vali, Sutter, Abrahams

Note: This paper was adopted into draft C++14 on Saturday at the Bristol UK ISO C++ meeting.

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

Date: 2013-04-19

Generic (Polymorphic) Lambda Expressions (Revision 3)

by Faisal Vali, Herb Sutter, Dave Abrahams

Excerpt:

This document revises wording for generic lambda expressions as described in N3559: Proposal for Generic (Polymorphic) Lambda Expressions (Revision 2) and as approved by EWG and which should be referenced for further detail.  Today’s C++11 lambda expression concisely creates an instance of a class having a non-template function call operator.  We propose a pure extension of C++11 lambda syntax that creates an instance of a class having a function call operator template. 

Here follow some examples of the proposed syntax extension in use:

// 'Identity' is a lambda that accepts an argument of any type and
// returns the value of its parameter. 
auto Identity = [](auto a) { return a; };
int three = Identity(3);
char const* hello = Identity("hello");

// Conversion to function pointer for capture-less lambdas
int (*fpi)(int) = Identity;
char (*fpc)(char) = Identity;

New adopted paper: N3651, Variable Templates (Revision 1) -- Gabriel Dos Reis

Note: This paper was adopted into draft C++14 on Saturday at the Bristol UK ISO C++ meeting.

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

Date: 2013-04-19

Variable Templates (Revision 1)

by Gabriel Dos Reis

Excerpt:

C++ has no notation for parameterized constants as direct as for functions or classes. For instance, we would like to represent the mathematical constant with precision dictated by a floating point datatype

template<typename T>
constexpr T pi = T(3.1415926535897932385);

and use it in generic functions, e.g. to compute the area of a circle with a given radius:

template<typename T>
T area_of_circle_with_radius(T r) {
    return pi<T> * r * r;
}

The types of variable templates are not restricted to just builtin types; they can
be user defined types. ...

This report proposes a simple extension to C++: allow variable templates. It makes definitions and uses of parameterized constants much simpler, leading to simplified and more uniform programming rules to teach and to remember.

New adopted paper: N3652, Relaxing Constraints on constexpr Functions -- Richard Smith

Note: This paper was adopted into draft C++14 on Saturday at the Bristol UK ISO C++ meeting.

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

Date: 2013-04-18

Relaxing constraints on constexpr functions

by Richard Smith

This is a major extension to constexpr. Excerpt:

This paper describes the subset of N3597 selected for inclusion in C++14, relaxing a number of restrictions on constexpr functions. These changes all received overwhelmingly strong or unopposed support under review of the Evolution Working Group. It also incorporates Option 2 of N3598.

The changes selected by the Evolution Working Group were:

  • Allow declarations within constexpr functions, other than:
       static or thread_local variables
       uninitialized variables
  • Allow if and switch statements (but not goto)
  • Allow all looping statements: for (including range-based for), while, and do-while
  • Allow mutation of objects whose lifetime began within the constant expression evaluation.

In addition, in discussion of N3598, Option 2 was selected, which removes the rule that a constexpr non-static member function is implicitly const.

New adopted paper: N3648, Wording Changes for Generalized Lambda-Capture -- Vandevoorde, Voutilainen

Note: This paper was adopted into draft C++14 on Saturday at the Bristol UK ISO C++ meeting.

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

Date: 2013-04-17

Wording Changes for Generalized Lambda-Capture

by Daveed Vandevoorde and Ville Voutilainen

NOTE: This paper is standardese only. For a description of the feature, see N3610, Generic Lambda-capture Initializers, Supporting Capture-by-move.

New adopted paper: N3638, Return Type Deduction for Normal Functions -- Jason Merrill

Note: This paper was adopted into draft C++14 on Saturday at the Bristol UK ISO C++ meeting.

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

Date: 2013-04-17

Return type deduction for normal functions

by Jason Merrill

Excerpt:

Any C++ user introduced to the C++11 features of auto, lambdas, and trailing return types immediately wonders why they can't just write auto on their function declaration and have the return type deduced. This functionality was proposed previously in N2954, but dropped from C++11 due to time constraints, as the drafting didn't address various questions and concerns that the Core WG had. I have now implemented this functionality in GCC, and propose to add it to C++14. I discuss some of the less obvious aspects of the semantics below.

This proposal also resolves core DRs 975 (lambda return type deduction from multiple return statements), 1048 (inconsistency between auto and lambda return type deduction), and 1588 (deducing cv-qualified auto).

Note that this paper also allows lambdas (not just functions) with multiple return statements to have their return type deduced. Examples in the paper include multiple returns, recursion, and more:

auto iterate(int len)                        // return type is deduced as int
{
  for (int i = 0; i < len; ++i)
    if (search (i))
      return i;
  return -1;
}

auto sum(int i) {
  if (i == 1)
    return i;                                // return type deduced to int
  else
    return sum(i-1)+i;                       // ok to call it recursively now
}

template <class T> auto f(T t) { return t; } // return type deduced at instantiation time

[]()->auto& { return f(); }                  // return a reference

New adopted paper: N3662, C++ Dynamic Arrays (dynarray) -- Lawrence Crowl, Matt Austern

Note: This paper was adopted into draft C++14 on Saturday at the Bristol UK ISO C++ meeting.

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

Date: 2013-04-19

C++ Dynamic Arrays

by Lawrence Crowl and Matt Austern

See also related paper N3662, "Runtime-Sized Arrays with Automatic Storage Duration (Revision 5)"

Excerpt:

Instead of adopting C variable-length arrays, we propose to define a new facility for arrays where the number of elements is bound at construction. We call these dynamic arrays, dynarray. In keeping with C++ practice, we wish to make dynarrays usable with more than just automatic variables. But to take advantage of the efficiency stack allocation, we wish to make dynarray optimizable when used as an automatic variable.