Document number: N1861=05-0121

Howard E. Hinnant
2005-08-26

Rvalue Reference Recommendations for Chapter 26

Contents

Related papers

Rvalue Reference Recommendations for Chapter 20
Rvalue Reference Recommendations for Chapter 21
Rvalue Reference Recommendations for Chapter 23
Rvalue Reference Recommendations for Chapter 24
Rvalue Reference Recommendations for Chapter 25
Rvalue Reference Recommendations for Chapter 27

Introduction

This paper recommends proposed wording with respect to the rvalue reference for the C++0X working draft. This paper restricts its scope to Chapter 26 "Numerics library" for the purpose of breaking the library work associated with the rvalue reference up into manageable chunks. This paper largely follows the lead of N1771: Impact of the rvalue reference on the Standard Library, but adds more detail as appropriate.

With the exception of this introduction, all non-proposed wording will have a background color and formatting that

looks like this, so that motivation and description is more easily distinguished from proposed wording.

In the proposed wording below, text to be inserted is formatted like this, while wording to be deleted is formatted like this.

The proposed wording in this paper simply adds to the class template valarray:

26.3 - Numeric arrays

26.3.1 - Header <valarray> synopsis

  ...
  template<class T> class indirect_array;   //  an indirected array

  template<T> void swap(valarray<T>&, valarray<T>&);
  template<T> void swap(valarray<T>&&, valarray<T>&);
  template<T> void swap(valarray<T>&, valarray<T>&&);

  template<class T> valarray<T> operator*
    (const valarray<T>&, const valarray<T>&);
  ...

26.3.2 - Class template valarray

namespace std {
  template<class T> class valarray {
  public:
    typedef T value_type;

    //  lib.valarray.cons construct/destroy:
    valarray();
    explicit valarray(size_t);
    valarray(const T&, size_t);
    valarray(const T*, size_t);
    valarray(const valarray&);
    valarray(valarray&&);
    valarray(const slice_array<T>&);
    valarray(const gslice_array<T>&);
    valarray(const mask_array<T>&);
    valarray(const indirect_array<T>&);
   ~valarray();

    //  lib.valarray.assign assignment:
    valarray<T>& operator=(const valarray<T>&);
    valarray& operator=(valarray&&);
    valarray<T>& operator=(const T&);
    valarray<T>& operator=(const slice_array<T>&);
    valarray<T>& operator=(const gslice_array<T>&);
    valarray<T>& operator=(const mask_array<T>&);
    valarray<T>& operator=(const indirect_array<T>&);

    void swap(valarray&&);

    //  lib.valarray.access element access:
    T                 operator[](size_t) const;
    T&                operator[](size_t);
    ...

26.3.2.1 - valarray constructors

...

valarray(const valarray<T>&);

-5- The array created by this constructor has the same length as the argument array. The elements are initialized with the values of the corresponding elements of the argument array.*

[Footnote: This copy constructor creates a distinct array rather than an alias. Implementations in which arrays share storage are permitted, but they shall implement a copy-on-reference mechanism to ensure that arrays are conceptually distinct. --- end footnote]

valarray(valarray&& v);

-6- The array created by this constructor has the same length as the argument array. The elements are initialized with the values of the corresponding elements of the argument array. The value of v after the construction is not specified.

-7- Complexity: Constant.

-8- Throws: Nothing.

...

26.3.2.2 - valarray assignment

valarray<T>& operator=(const valarray<T>&);

-1- Each element of the *this array is assigned the value of the corresponding element of the argument array. The resulting behavior is undefined if the length of the argument array is not equal to the length of the *this array.


valarray& operator=(valarray&& v);

-2- Effects: *this obtains the value of v. The value of v after the assignment is not specified.

-3- Complexity: Constant.

-4- Throws: Nothing.

26.3.2.7 - valarray member functions


void swap(valarray&& v);

-10- Effects: *this obtains the value of v. The value of v obtains the value of *this.

-11- Complexity: Constant.

-12- Throws: Nothing.

26.3.3 - valarray non-member functions

26.3.3.4 - valarray specialized algorithms


template<T> void swap(valarray<T>& x, valarray<T>& y);
template<T> void swap(valarray<T>&& x, valarray<T>& y);
template<T> void swap(valarray<T>& x, valarray<T>&& y);

-1- Effects: x.swap(y).