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


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


Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.