VectorExpression concept

Description

A vector expression is an expression which after computation results in a vector. Thus a vector expression can be assigned to a vector collection.

Refinement of

Expression.

Associated types

Value type X::value_type [1] The type of the entries in the expression
Const reference type X::const_reference const lvalue of value_type [2]
Size type X::size_type The type of the indices. The size_type must be a signed or unsigned integer type [3]

Notation

X Type that is a model of Expression
a Objects of type X

Definitions

Valid expressions

Name Expression Type requirements Return type
Size a.size() [3] size_type
Element access a[i] const_reference
Element access a(i) const_reference

Expression semantics

Name Expression Precondition Semantics Postcondition
Size a.size() Returns the current size of the collection [3] a.size()>=0
Element access a[i] 0≤i and i<a.size() Returns the value at the given index
Element access a(i) 0≤i and i<a.size() Returns the value at the given index

Complexity guarantees

Invariants

Models

Notes

[1] Although the value_type is not used directly in the operations of the VectorExpression, having the value_type makes the implementation of the value meta-function easier and improves compatibility with the std::vector.

[2] The const_reference is defined identically tot the const_reference in the standard's container requirements. Remark that this does not necessitate const_reference to be defined as 'value_type const &'. Since expressions by definition calculate the expression only when it's asked for and never store the result a reference to the (stored) result is impossible.

[3] The size() member-function and size_type are not really necessary since the Expression already provides a free size(a) function and a size<X>::type meta-function but this improves compatibility and the former can be used to implement the latter.