std::end(std::valarray)(3)
okay so bestie, this is std::end(std::valarray)(3) from the C++ Standard Libary manual β yes, that spelling is literally in the header and we are not fixing it, we respect the iconique typo π
. It's giving βtiny overload with big range-for energy,β and weβre gonna go through every single detail together. π«Ά
π NAME π
std::end(std::valarray) - literally std::end(std::valarray), no cap. Thatβs the whole name, bestie. β¨
β¨ Synopsis β¨
template< class T > (1) (since C++11)
/* see below */ end( valarray<T>& v );
template< class T > (2) (since C++11)
/* see below */ end( const valarray<T>& v );
The overload of std::end for valarray returns an iterator of unspecified type referring to the one past the last element in the numeric array. So itβs the βendβ iterator vibe, but the exact type is a mystery β unspecified, not our business, moving on. π«
- The return type must
- meet the requirements of mutable
LegacyRandomAccessIterator, - model
contiguous_iterator, (since C++20) - have a member type
value_type, which isT, and - have a member type
reference, which isT&.
- meet the requirements of mutable
- The return type must
- meet the requirements of constant
LegacyRandomAccessIterator, - model
contiguous_iterator, (since C++20) - have a member type
value_type, which isT, and - have a member type
reference, which isconst T&.
- meet the requirements of constant
lowkey important, bestie: the iterator returned from this function is invalidated when the member functionresize()is called onvor when the lifetime ofvends, whichever comes first. So donβt hold onto it like itβs a forever text, because it is not π.
π Parameters π
vβ a numeric array. Thatβs it. Thatβs the parameter. Slay. πΈ
πΈ Return value πΈ
Iterator to one past the last value in the numeric array. Classic end-of-range behavior, no notes. π
π¦ Exceptions π¦
May throw implementation-defined exceptions. So likeβ¦ ask your implementation, bestie. π¦
π Notes π
Unlike other functions that take std::valarray arguments, end() cannot accept the replacement types (such as the types produced by expression templates) that may be returned from expressions involving valarrays: std::end(v1 + v2) is not portable, and std::end(std::valarray<T>(v1 + v2)) has to be used instead. So donβt try to be cute with std::end(v1 + v2) in portable code, because itβs giving not-portable vibes and we donβt do that. π
The intent of this function is to allow range for loops to work with valarrays, not to provide container semantics. So itβs a range-for helper, not a whole container glow-up. Periodt. π
π Example π
Run this code, bestie:
// Run this code
#include <algorithm>
#include <iostream>
#include <valarray>
int main()
{
const std::valarray<char> va
{
'H', 'e', 'l', 'l', 'o',
',', ' ',
'C', '+', '+', '!', '\n'
};
std::for_each(std::begin(va), std::end(va),
[](char c){ std::cout << c; });
}
β Output β
Hello, C++!
π₯ Defect reports π₯
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. This is the βwe fixed it after the factβ section, and it ate. π
- DR
LWG 2058β applied to C++11- 1. behavior as published:
end()was required to support replacement types β correct behavior: 1. not required - 2. behavior as published: it was unspecified when the returned iterators will be invalidated β correct behavior: 2. specified
- 1. behavior as published:
π See also π
std::begin(std::valarray)β overloadsstd::begin(C++11) (function template)
mwah π β source: http://cppreference.com, version/date: 2024.06.10, page: std::end(std::valarray)(3). Thatβs the footer, bestie, and thatβs the whole vibe. periodt. π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms