std::indire...::operator=(3)
π NAME π
okay so this is the page for std::indire...::operator=(3), from the C++ Standard Libary manual. The name is literally std::indirect_array::operator= β yes, std::indirect_array::operator=. It's giving indirect-array assignment realness π
β¨ Synopsis β¨
bestie, there are three overloads, and the whole vibe is assigns values to all referred elements:
void operator=( const T& value ) const;
(1)
void operator=( const std::valarray<T>& val_arr ) const;
(2)
const indirect_array& operator=( const indirect_array& other_arr ) const;
(3)
πΈ What each overload does πΈ
- Assigns
valueto all of the elements. <em>all</em> of them, no cap π - Assigns the elements of
val_arrto the referred to elements of*this. - Assigns the selected elements from
other_arrto the referred to elements of*this.
π Parameters π
valueβ a value to assign to all of the referred elementsval_arrβstd::valarrayto assignother_arrβstd::indirect_arrayto assign
π«Ά Return value π«Ά
- (1), (2) β (none)
- (3) β
*this
π¦ Example π¦
// Run this code π
#include <iomanip>
#include <iostream>
#include <numeric>
#include <valarray>
void print(int n, std::valarray<int> const& v)
{
std::cout << n << ':';
for (int e : v)
std::cout << std::setw(3) << e;
std::cout << '\n';
}
int main()
{
std::valarray<int> v(8);
std::iota(std::begin(v), std::end(v), 0);
print(1, v);
std::valarray<std::size_t> idx{1, 3, 5, 7};
const std::indirect_array<int> ia = v[idx];
// 'ia' refers to v[1], v[3], v[5], v[7]
ia = -1; // (1), effectively:
// v[1] = v[3] = v[5] = v[7] = -1;
print(2, v);
ia = /*std::valarray<int>*/{-1, -2, -3, -4}; // (2),
// effectively: v[1] = -1, v[3] = -2, v[5] = -3, v[7] = -4;
print(3, v);
std::valarray<std::size_t> idx2{0, 2, 4, 6};
const std::indirect_array<int> ia2 = v[idx2];
// 'ia2' refers to v[0], v[2], v[4], v[6]
ia = ia2; // (3), effectively:
// v[1] = v[0], v[3] = v[2], v[5] = v[4], v[7] = v[6];
print(4, v);
}
π Output π
1: 0 1 2 3 4 5 6 7
2: 0 -1 2 -1 4 -1 6 -1
3: 0 -1 2 -2 4 -3 6 -4
4: 0 0 2 2 4 4 6 6
π οΈ Defect reports π οΈ
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- LWG 123, applied to C++98 β behavior as published: overload (2) was non-const. Correct behavior: made const.
- LWG 253, applied to C++98 β behavior as published: the copy assignment operator was private. Correct behavior: made public.
- LWG 621, applied to C++98 β behavior as published: the copy assignment operator was non-const. Correct behavior: made const.
okay bestie that's the whole page π the footer title is std::indire...::operator=(3), the source is http://cppreference.com, and the version/date is 2024.06.10. go assign something iconic β¨
π¦ 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