26 Numerics library [numerics]

26.2 Numeric type requirements [numeric.requirements]

The complex and valarray components are parameterized by the type of information they contain and manipulate. A C++ program shall instantiate these components only with a type T that satisfies the following requirements:273

  • T is not an abstract class (it has no pure virtual member functions);

  • T is not a reference type;

  • T is not cv-qualified;

  • If T is a class, it has a public default constructor;

  • If T is a class, it has a public copy constructor with the signature T::T(const T&)

  • If T is a class, it has a public destructor;

  • If T is a class, it has a public assignment operator whose signature is either T& T::operator=(const T&) or T& T::operator=(T)

  • If T is a class, its assignment operator, copy and default constructors, and destructor shall correspond to each other in the following sense: Initialization of raw storage using the default constructor, followed by assignment, is semantically equivalent to initialization of raw storage using the copy constructor. Destruction of an object, followed by initialization of its raw storage using the copy constructor, is semantically equivalent to assignment to the original object.

    Note: This rule states that there shall not be any subtle differences in the semantics of initialization versus assignment. This gives an implementation considerable flexibility in how arrays are initialized.

    Example: An implementation is allowed to initialize a valarray by allocating storage using the new operator (which implies a call to the default constructor for each element) and then assigning each element its value. Or the implementation can allocate raw storage and use the copy constructor to initialize each element.  — end example ]

    If the distinction between initialization and assignment is important for a class, or if it fails to satisfy any of the other conditions listed above, the programmer should use vector ([vector]) instead of valarray for that class;  — end note ]

  • If T is a class, it does not overload unary operator&.

If any operation on T throws an exception the effects are undefined.

In addition, many member and related functions of valarray<T> can be successfully instantiated and will exhibit well-defined behavior if and only if T satisfies additional requirements specified for each such member or related function.

Example: It is valid to instantiate valarray<complex>, but operator>() will not be successfully instantiated for valarray<complex> operands, since complex does not have any ordering operators.  — end example ]

In other words, value types. These include arithmetic types, pointers, the library class complex, and instantiations of valarray for value types.