Common mathematical functions | |||||||||||||||||||||||||||||||
Mathematical special functions(C++17) | |||||||||||||||||||||||||||||||
Mathematical constants(C++20) | |||||||||||||||||||||||||||||||
Basic linear algebra algorithms(C++26) | |||||||||||||||||||||||||||||||
Data-parallel types (SIMD)(C++26) | |||||||||||||||||||||||||||||||
Floating-point environment(C++11) | |||||||||||||||||||||||||||||||
Complex numbers | |||||||||||||||||||||||||||||||
Numeric array (valarray ) | |||||||||||||||||||||||||||||||
Pseudo-random number generation | |||||||||||||||||||||||||||||||
Bit manipulation(C++20) | |||||||||||||||||||||||||||||||
Saturation arithmetic(C++26) | |||||||||||||||||||||||||||||||
Factor operations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Interpolations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Generic numeric operations | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
C-style checked integer arithmetic | |||||||||||||||||||||||||||||||
|
template<class T> /* see below */ begin( valarray<T>& v); | (1) | (since C++11) |
template<class T> /* see below */ begin(const valarray<T>& v); | (2) | (since C++11) |
The overload ofstd::begin forvalarray
returns an iterator of unspecified type referring to the first element in the numeric array.
| (since C++20) |
value_type
, which isT
, andreference
, which isT&
.
| (since C++20) |
value_type
, which isT
, andreference
, which isconst T&
.The iterator returned from this function is invalidated when the member functionresize()
is called onv or when the lifetime ofv ends, whichever comes first.
Contents |
v | - | a numeric array |
Iterator to the first value in the numeric array.
May throw implementation-defined exceptions.
Unlike other functions that takestd::valarray
arguments,begin()
cannot accept the replacement types (such as the types produced by expression templates) that may be returned from expressions involving valarrays:std::begin(v1+ v2) is not portable,std::begin(std::valarray<T>(v1+ v2)) has to be used instead.
The intent of this function is to allowrange for loops to work with valarrays, not to provide container semantics.
#include <algorithm>#include <iostream>#include <valarray> void show(conststd::valarray<int>& v){std::for_each(std::begin(v),std::end(v),[](int c){std::cout<< c<<' ';});std::cout<<'\n';}; int main(){conststd::valarray<int> x{47,70,37,52,90,23,17,33,22,16,21,4};conststd::valarray<int> y{25,31,71,56,21,21,15,34,21,27,12,6}; show(x); show(y); conststd::valarray<int> z{x+ y}; for(char c: z)std::cout<< c;}
Output:
47 70 37 52 90 23 17 33 22 16 21 4 25 31 71 56 21 21 15 34 21 27 12 6 Hello, C++!
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 2058 | C++11 | 1.begin() was required to support replacement types2. it was unspecified when the returned iterators will be invalidated | 1. not required 2. specified |
(C++11) | specializesstd::end (function template)[edit] |