Title
{variant,optional,any}::emplace should return the constructed value
Status
c++17
Section
[optional][variant][any]
Submitter
Zhihao Yuan

Created on 2017-01-25.00:00:00 last changed 80 months ago

Messages

Date: 2017-03-03.22:19:58

Proposed resolution:

This wording is relative to N4618.

  1. Update the following signatures in [optional.optional], class template optional synopsis, as indicated:

    […]
    // [optional.assign], assignment
    […]
    template <class... Args> voidT& emplace(Args&&...);
    template <class U, class... Args>
      voidT& emplace(initializer_list<U>, Args&&...);
    […]
    
  2. Modify [optional.assign] as indicated:

    template <class... Args> voidT& emplace(Args&&... args);
    

    […]

    -27- Postconditions: *this contains a value.

    -?- Returns: A reference to the new contained value.

    -28- Throws: Any exception thrown by the selected constructor of T.

    template <class U, class... Args> voidT& emplace(initializer_list<U> il, Args&&... args);
    

    […]

    -31- Postconditions: *this contains a value.

    -?- Returns: A reference to the new contained value.

    -32- Throws: Any exception thrown by the selected constructor of T.

  3. Modify the following signatures in [variant.variant], class template variant synopsis, as indicated:

    […]
    // [variant.mod], modifiers
    template <class T, class... Args> voidT& emplace(Args&&...);
    template <class T, class U, class... Args>
      voidT& emplace(initializer_list<U>, Args&&...);
    template <size_t I, class... Args> voidvariant_alternative_t<I, variant<Types...>>& emplace(Args&&...);
    template <size_t I, class U, class... Args>
      voidvariant_alternative_t<I, variant<Types...>>& emplace(initializer_list<U>, Args&&...);
    […]
    
  4. Modify [variant.mod] as indicated:

    template <class T, class... Args> voidT& emplace(Args&&... args);
    

    -1- Effects: Equivalent to return emplace<I>(std::forward<Args>(args)...); where I is the zero-based index of T in Types....

    […]

    template <class T, class U, class... Args>
      voidT& emplace(initializer_list<U> il, Args&&... args);
    

    -3- Effects: Equivalent to return emplace<I>(il, std::forward<Args>(args)...); where I is the zero-based index of T in Types....

    […]

    template <size_t I, class... Args> voidvariant_alternative_t<I, variant<Types...>>& emplace(Args&&... args);
    

    […]

    -7- Postconditions: index() is I.

    -?- Returns: A reference to the new contained value.

    -8- Throws: Any exception thrown during the initialization of the contained value.

    […]

    template <size_t I, class U, class... Args>
      voidvariant_alternative_t<I, variant<Types...>>& emplace(initializer_list<U> il, Args&&... args);
    

    […]

    -12- Postconditions: index() is I.

    -?- Returns: A reference to the new contained value.

    -13- Throws: Any exception thrown during the initialization of the contained value.

    […]

  5. Modify the following signatures in [any.class], class any synopsis, as indicated:

    […]
    // [any.modifiers], modifiers
    template <class ValueType, class... Args>
      voiddecay_t<ValueType>& emplace(Args&& ...);
    template <class ValueType, class U, class... Args>
      voiddecay_t<ValueType>& emplace(initializer_list<U>, Args&&...);
    […]
    
  6. Modify [any.modifiers] as indicated:

    template <class ValueType, class... Args>
      voiddecay_t<ValueType>& emplace(Args&&... args);
    

    […]

    -4- Postconditions: *this contains a value.

    -?- Returns: A reference to the new contained value.

    -5- Throws: Any exception thrown by the selected constructor of T.

    […]

    template <class ValueType, class U, class... Args>
      voiddecay_t<ValueType>& emplace(initializer_list<U> il, Args&&... args);
    

    […]

    -10- Postconditions: *this contains a value.

    -?- Returns: A reference to the new contained value.

    -11- Throws: Any exception thrown by the selected constructor of T.

    […]

Date: 2017-03-03.22:19:58

[ Kona 2017-03-02 ]

Accepted as Immediate because P1.

Date: 2017-01-27.00:00:00

[ 2017-01-27 Telecon ]

Priority 1; send to LEWG.

Date: 2017-01-25.00:00:00

When you want to continue operate on the new contained object constructed by emplace, you probably don't want to go through the type-safe machinery again.

History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2017-03-05 23:46:08adminsetstatus: immediate -> wp
2017-03-03 22:19:58adminsetmessages: + msg9072
2017-03-03 22:19:58adminsetstatus: lewg -> immediate
2017-01-30 15:36:02adminsetmessages: + msg8833
2017-01-30 15:36:02adminsetstatus: new -> lewg
2017-01-26 19:43:37adminsetmessages: + msg8795
2017-01-25 00:00:00admincreate