Title
Move-construction with raw_storage_iterator
Status
c++17
Section
[depr.storage.iterator]
Submitter
Jonathan Wakely

Created on 2012-01-23.00:00:00 last changed 81 months ago

Messages

Date: 2015-05-07.20:33:29

Proposed resolution:

This wording is relative to N4140.

  1. Add a new signature to the synopsis in [storage.iterator] p1:

    namespace std {
      template <class OutputIterator, class T>
      class raw_storage_iterator
        : public iterator<output_iterator_tag,void,void,void,void> {
      public:
        explicit raw_storage_iterator(OutputIterator x);
    
        raw_storage_iterator<OutputIterator,T>& operator*();
        raw_storage_iterator<OutputIterator,T>& operator=(const T& element);
        raw_storage_iterator<OutputIterator,T>& operator=(T&& element);
        raw_storage_iterator<OutputIterator,T>& operator++();
        raw_storage_iterator<OutputIterator,T> operator++(int);
    };
    }
    
  2. Insert a new paragraph before p4:

    raw_storage_iterator<OutputIterator,T>& operator=(const T& element);
    

    -?- Requires: T shall be CopyConstructible.

    -4- Effects: Constructs a value from element at the location to which the iterator points.

    -5- Returns: A reference to the iterator.

  3. Insert the new signature and a new paragraph after p5:

    raw_storage_iterator<OutputIterator,T>& operator=(T&& element);
    

    -?- Requires: T shall be MoveConstructible.

    -?- Effects: Constructs a value from std::move(element) at the location to which the iterator points.

    -?- Returns: A reference to the iterator.

Date: 2015-05-07.20:33:29

[ 2015-05, Lenexa ]

MC: Suggestion to move it to Ready for incorporation on Friday
MC: move to ready: in favor: 12, opposed: 0, abstain: 3

Date: 2014-11-15.00:00:00

[ 2014-11-11, Jonathan provides improved wording ]

In Urbana LWG decided to explicitly say the value is constructed from an rvalue.

Previous resolution from Jonathan [SUPERSEDED]:

This wording is relative to N3337.

  1. Add a new signature to the synopsis in [storage.iterator] p1:

    namespace std {
      template <class OutputIterator, class T>
      class raw_storage_iterator
        : public iterator<output_iterator_tag,void,void,void,void> {
      public:
        explicit raw_storage_iterator(OutputIterator x);
    
        raw_storage_iterator<OutputIterator,T>& operator*();
        raw_storage_iterator<OutputIterator,T>& operator=(const T& element);
        raw_storage_iterator<OutputIterator,T>& operator=(T&& element);
        raw_storage_iterator<OutputIterator,T>& operator++();
        raw_storage_iterator<OutputIterator,T> operator++(int);
    };
    }
    
  2. Insert the new signature and a new paragraph before p4:

    raw_storage_iterator<OutputIterator,T>& operator=(const T& element);
    raw_storage_iterator<OutputIterator,T>& operator=(T&& element);
    

    -?- Requires: For the first signature T shall be CopyConstructible. For the second signature T shall be MoveConstructible.

    -4- Effects: Constructs a value from element at the location to which the iterator points.

    -5- Returns: A reference to the iterator.

Date: 2012-02-05.16:10:07

Aliaksandr Valialkin pointed out that raw_storage_iterator only supports constructing a new object from lvalues so cannot be used to construct move-only types:

template <typename InputIterator, typename T>
void move_to_raw_buffer(InputIterator first, InputIterator last, T *raw_buffer)
{
  std::move(first, last, std::raw_storage_iterator<T *, T>(raw_buffer));
}

This could easily be solved by overloading operator= for rvalues.

Dave Abrahams:

raw_storage_iterator causes exception-safety problems when used with any generic algorithm. I suggest leaving it alone and not encouraging its use.

History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2015-10-27 16:52:45adminsetstatus: ready -> wp
2015-05-07 20:33:29adminsetmessages: + msg7378
2015-05-07 20:33:29adminsetstatus: open -> ready
2014-11-17 21:07:14adminsetmessages: + msg7192
2012-02-12 18:36:43adminsetstatus: new -> open
2012-02-05 15:29:47adminsetmessages: + msg5988
2012-01-23 00:00:00admincreate