valarray(3)
π NAME π
valarray β ok so bestie, the name is literally just valarray and that's it. The description slot is giving crickets π¦ β the original page leaves it blank, so we're not inventing one. No cap, it's just vibes and a name. Everything you actually need is in the SYNOPSIS below. π
This is the valarray(3) page, from the Library Functions Manual, and it comes in three parts β this is part 1, so don't go anywhere. π«Ά
β¨ SYNOPSIS β¨
π Classes
class std::valarray< _Tp >β a smart array designed to support numeric processing. That's the whole pitch, and honestly? Iconic. π
π¦ Namespaces
namespace stdβ yes queen, the one and only. Everything here lives inside it.
πΈ Defines
These are the preprocessor macros, and they show up exactly like this β character for character, no edits, we do not touch the source:
#define _DEFINE_BINARY_OPERATOR(_Op, _Name)
#define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name)
#define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name)
#define _DEFINE_VALARRAY_UNARY_OPERATOR(_Op, _Name)
#define _GLIBCXX_VALARRAY
A whole little macro family:
_DEFINE_BINARY_OPERATOR(_Op, _Name)β binary operator vibes π«_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name)β augmented assignment, but make it valarray π_DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name)β the same energy, expression-flavoured β¨_DEFINE_VALARRAY_UNARY_OPERATOR(_Op, _Name)β unary operators, solo main character energy π_GLIBCXX_VALARRAYβ the guard-ish one, lowkey the bouncer at the club letting the rest in π₯
Heads up bestie: these are internal-looking macros, so treat them as exactly what the header spells β we're not guessing what they expand to, because this page doesn't say. π
That's part 1 wrapped, but we're not done β more parts follow, so stay tuned. π
Alright bestie, we're in the Functions zone now, and this is where <valarray> shows off π
Every single one of these is a template<typename _Tp > free function living in std::, and every single one hands you back an _Expr<...> β that's the lazy expression-template magic, not an actual computed array. Three flavours each, always in this order: scalar on the left, scalar on the right, and array-vs-array. No skipping, we're doing all of them. π«Ά
π« operator!= β the "you are NOT equal" bestie
Three overloads, same deal every time: __not_equal_to gets wrapped up in _BinClos, and __fun< __not_equal_to, _Tp >::result_type tells you what falls out.
template<typename _Tp > _Expr< _BinClos< __not_equal_to, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __not_equal_to, _Tp >::result_type > std::operator!= (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __not_equal_to, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __not_equal_to, _Tp >::result_type > std::operator!= (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __not_equal_to, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __not_equal_to, _Tp >::result_type > std::operator!= (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
π° operator% β remainder era
Modulo, but make it broadcast. __modulus all day.
template<typename _Tp > _Expr< _BinClos< __modulus, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __modulus, _Tp >::result_type > std::operator% (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __modulus, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __modulus, _Tp >::result_type > std::operator% (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __modulus, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __modulus, _Tp >::result_type > std::operator% (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
π operator& β bitwise AND, but elementwise
__bitwise_and, three ways. Yes the ampersand does double duty in C++, no we're not getting into it right now π
template<typename _Tp > _Expr< _BinClos< __bitwise_and, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __bitwise_and, _Tp >::result_type > std::operator& (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __bitwise_and, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __bitwise_and, _Tp >::result_type > std::operator& (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __bitwise_and, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __bitwise_and, _Tp >::result_type > std::operator& (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
π§ operator&& β logical AND, per-element
__logical_and. Note this is the logical one, not the bitwise one β different vibe, different functor, iykyk.
template<typename _Tp > _Expr< _BinClos< __logical_and, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __logical_and, _Tp >::result_type > std::operator&& (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __logical_and, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __logical_and, _Tp >::result_type > std::operator&& (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __logical_and, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __logical_and, _Tp >::result_type > std::operator&& (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
βοΈ operator* β multiplication slay
__multiplies. Scalar-broadcast both directions, plus array-times-array. (This is elementwise multiply, not some matrix nonsense π)
template<typename _Tp > _Expr< _BinClos< __multiplies, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __multiplies, _Tp >::result_type > std::operator* (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __multiplies, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __multiplies, _Tp >::result_type > std::operator* (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __multiplies, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __multiplies, _Tp >::result_type > std::operator* (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
β operator+ β the classic
__plus. Our beloved. Three overloads, exactly like you'd expect.
template<typename _Tp > _Expr< _BinClos< __plus, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __plus, _Tp >::result_type > std::operator+ (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __plus, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __plus, _Tp >::result_type > std::operator+ (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __plus, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __plus, _Tp >::result_type > std::operator+ (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
β operator- β minus, iconic
__minus, same trio. Careful, order matters when it's not commutative, bestie π
template<typename _Tp > _Expr< _BinClos< __minus, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __minus, _Tp >::result_type > std::operator- (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __minus, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __minus, _Tp >::result_type > std::operator- (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __minus, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __minus, _Tp >::result_type > std::operator- (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
β operator/ β division, handle with care
__divides. Same three shapes. Scalar-on-the-left exists too, so 2 / some_valarray is a whole thing.
template<typename _Tp > _Expr< _BinClos< __divides, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __divides, _Tp >::result_type > std::operator/ (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __divides, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __divides, _Tp >::result_type > std::operator/ (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __divides, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __divides, _Tp >::result_type > std::operator/ (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
π operator< β less-than moment
__less. Elementwise comparison, results come back in the expression's result_type.
template<typename _Tp > _Expr< _BinClos< __less, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __less, _Tp >::result_type > std::operator< (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __less, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __less, _Tp >::result_type > std::operator< (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __less, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __less, _Tp >::result_type > std::operator< (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
πͺοΈ operator<< β shift left, but on arrays
__shift_left. Not the stream operator. Do not come for me, I know what you're thinking π
template<typename _Tp > _Expr< _BinClos< __shift_left, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __shift_left, _Tp >::result_type > std::operator<< (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __shift_left, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __shift_left, _Tp >::result_type > std::operator<< (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __shift_left, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __shift_left, _Tp >::result_type > std::operator<< (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
π operator<= β less-or-equal
__less_equal, three overloads. Yes, even the scalar-first one. Yes, it's cute.
template<typename _Tp > _Expr< _BinClos< __less_equal, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __less_equal, _Tp >::result_type > std::operator<= (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __less_equal, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __less_equal, _Tp >::result_type > std::operator<= (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __less_equal, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __less_equal, _Tp >::result_type > std::operator<= (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
π operator== β equality bestie
__equal_to. The one you'll actually use in a while loop when something's not cooperating.
template<typename _Tp > _Expr< _BinClos< __equal_to, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __equal_to, _Tp >::result_type > std::operator== (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __equal_to, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __equal_to, _Tp >::result_type > std::operator== (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __equal_to, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __equal_to, _Tp >::result_type > std::operator== (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
π operator> β greater than energy
__greater. Main character operator fr fr.
template<typename _Tp > _Expr< _BinClos< __greater, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __greater, _Tp >::result_type > std::operator> (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __greater, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __greater, _Tp >::result_type > std::operator> (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __greater, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __greater, _Tp >::result_type > std::operator> (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
π operator>= β greater-or-equal
__greater_equal, and yes, all three forms, we're committed π
template<typename _Tp > _Expr< _BinClos< __greater_equal, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __greater_equal, _Tp >::result_type > std::operator>= (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __greater_equal, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __greater_equal, _Tp >::result_type > std::operator>= (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __greater_equal, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __greater_equal, _Tp >::result_type > std::operator>= (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
π¦ operator>> β shift right
__shift_right, the mirror of the earlier one. Also not a stream thing. Also extremely valid.
template<typename _Tp > _Expr< _BinClos< __shift_right, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __shift_right, _Tp >::result_type > std::operator>> (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __shift_right, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __shift_right, _Tp >::result_type > std::operator>> (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __shift_right, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __shift_right, _Tp >::result_type > std::operator>> (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
π operator^ β bitwise XOR
__bitwise_xor. Elementwise, obviously. Get into it.
template<typename _Tp > _Expr< _BinClos< __bitwise_xor, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __bitwise_xor, _Tp >::result_type > std::operator^ (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __bitwise_xor, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __bitwise_xor, _Tp >::result_type > std::operator^ (const valarray< _Tp > &__v, const _Tp &__t)
template<typename _Tp > _Expr< _BinClos< __bitwise_xor, _ValArray, _ValArray, _Tp, _Tp >, typename __fun< __bitwise_xor, _Tp >::result_type > std::operator^ (const valarray< _Tp > &__v, const valarray< _Tp > &__w)
π§ operator| β bitwise OR
__bitwise_or. Scalar on the left, scalar on the right β and the array-vs-array one is right there in the next bit, don't worry, we're not ghosting you π«Ά
template<typename _Tp > _Expr< _BinClos< __bitwise_or, _Constant, _ValArray, _Tp, _Tp >, typename __fun< __bitwise_or, _Tp >::result_type > std::operator| (const _Tp &__t, const valarray< _Tp > &__v)
template<typename _Tp > _Expr< _BinClos< __bitwise_or, _ValArray, _Constant, _Tp, _Tp >, typename __fun< __bitwise_or, _Tp >::result_type > std::operator| (const valarray< _Tp > &__v, const _Tp &__t)
...and last up, the logic-gate besties β the ones that take your whole valarray and go "and?" / "or?" at it like it's nothing π
operator|β bitwise OR, except it's lowkey elementwise and returns a lazy expression instead of a real vector. Lazy girl math, but make it templated β¨
template<typename _Tp > _Expr< _BinClos< __bitwise_or, _ValArray,
_ValArray, _Tp, _Tp >, typename __fun< __bitwise_or, _Tp
>::result_type > std::operator| (const valarray< _Tp > &__v, const
valarray< _Tp > &__w)
operator||(constant on the left, valarray on the right) β logical OR, and yes bestie, the scalar gets to go first π«Ά
template<typename _Tp > _Expr< _BinClos< __logical_or, _Constant,
_ValArray, _Tp, _Tp >, typename __fun< __logical_or, _Tp
>::result_type > std::operator|| (const _Tp &__t, const valarray<
_Tp > &__v)
operator||(valarray on the left, constant on the right) β same energy, mirrored. The valarray is the main character this time π
template<typename _Tp > _Expr< _BinClos< __logical_or, _ValArray,
_Constant, _Tp, _Tp >, typename __fun< __logical_or, _Tp
>::result_type > std::operator|| (const valarray< _Tp > &__v, const
_Tp &__t)
operator||(valarray on both sides) β full logical OR, element by element, bestie-on-bestie π
template<typename _Tp > _Expr< _BinClos< __logical_or, _ValArray,
_ValArray, _Tp, _Tp >, typename __fun< __logical_or, _Tp
>::result_type > std::operator|| (const valarray< _Tp > &__v, const
valarray< _Tp > &__w)
πΈ Detailed Description πΈ
Okay so real talk β this whole thing? It's a Standard C++ Library header. That's it, that's the vibe. Iconic, standards-compliant, shipped with the compiler, no cap πβ¨
Definition in file valarray.
π Author π
Plot twist bestie, nobody wrote this page by hand:
Generated automatically by Doxygen for libstdc++ from the source code.
So if you spotted a typo, blame the robot ππ€
That's the whole page, bestie β go forth and valarray responsibly π¦π
π libstdc++ Β· 21 Apr 2009 Β· valarray(3) β mwah, see you in the next manpage π«ΆβοΈ
π¦ where this page comes from
- nixpkgs unstable: std-man-pages 4.4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms