April 2013

New adopted paper: N3672, std::optional (Revision 4) -- Fernando Cacciola, Andrzej KrzemieĊ„ski

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

Date: 2013-04-19

A proposal to add a utility class to represent optional objects (Revision 4)

by Fernando Cacciola and Andrzej Krzemieński

Excerpt:

The basic usage of optional<T> can be illustrated with the following example.

optional<int> str2int(string);    // converts int to string if possible

int get_int_form_user()
{
  string s;

  for (;;) {
    cin >> s;
    optional<int> o = str2int(s); // 'o' may or may not contain an int
    if (o) {                      // does optional contain a value?
      return *o;                  // use the value
    }
  }
}

 

New adopted paper: N3655 (excluding part 4), TransformatinTraits Redux, v2 -- Walter Brown

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

Date: 2013-04-18

TransformationTraits Redux, v2

by Walter Brown

NOTE: Section 4 was not adopted.

Excerpt:

... We therefore propose to add a set of template aliases for the library’s TransformationTraits in order to reduce the programmer burden of expressing this far more common case. Note, in the following rewrite of the above example, the absence of any typename keyword, as well as the absence of any ::type suffix, thus condensing the statement from 3 to 2 lines of code:


template< class T > using reference_t
  = conditional_t< is_reference<T>::value, T, add_lvalue_reference_t<T> >;

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.