valarray(3)

πŸ“¦ version 4.4.0, in nixpkgs unstable

πŸ’– 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