std::slice_...y::operator=(3)
okay so this is the C++ Standard Libary manual page for std::slice_...y::operator=(3), and we're keeping the truncated-looking page name exactly as it appears. bestie, it's giving "slice assignment tea," and every overload is invited to the group chat π
πΈ NAME πΈ
std::slice_array::operator= β std::slice_array::operator=
β¨ SYNOPSIS β¨
void operator=( const T& value ) const;
(1)
void operator=( const std::valarray<T>& val_arr ) const;
(2)
const slice_array& operator=( const slice_array& other_arr ) const;
(3)
π DESCRIPTION π
These overloads assign values to all referred elements. no cap, that's the whole vibe:
- Assigns
valueto all of the elements. - 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::slice_arrayto assign
πΈ RETURN VALUE πΈ
1,2β (none)3β*this
π EXAMPLE π
// Run this code
#include <iostream>
#include <valarray>
void print(char const* remark, std::valarray<int> const& v = {})
{
std::cout << remark;
if (v.size() != 0)
{
std::cout << ':';
for (int e : v)
std::cout << ' ' << e;
}
std::cout << '\n';
}
int main()
{
std::valarray<int> v1{1, 2, 3, 4, 5, 6, 7, 8};
std::slice_array<int> s1 = v1[std::slice(1, 4, 2)];
print("v1", v1);
print("s1", s1);
print("\n(1) operator=( const T& )");
print("s1 = 42");
s1 = 42; // (1)
print("s1", s1);
print("v1", v1);
print("\n(2) operator=( const std::valarray<T>& )");
std::valarray<int> v2{10, 11, 12, 13, 14, 15};
print("v2", v2);
print("s1 = v2");
s1 = v2; // (2)
print("s1", s1);
print("v1", v1);
print("\n(3) operator=( const slice_array& )");
v1 = {1, 2, 3, 4, 5, 6, 7, 8};
std::slice_array<int> s2 = v1[std::slice(0, 4, 1)];
std::slice_array<int> s3 = v2[std::slice(1, 4, 1)];
print("v1", v1);
print("v2", v2);
print("s2", s2);
print("s3", s3);
print("s2 = s3");
s2 = s3; // (3) Note: LHS and RHS must have same size.
print("s2", s2);
print("v1", v1);
}
lowkey important note from the code: for overload(3),LHS and RHS must have same size.π«Ά
π OUTPUT π
v1: 1 2 3 4 5 6 7 8
s1: 2 4 6 8
(1) operator=( const T& )
s1 = 42
s1: 42 42 42 42
v1: 1 42 3 42 5 42 7 42
(2) operator=( const std::valarray<T>& )
v2: 10 11 12 13 14 15
s1 = v2
s1: 10 11 12 13
v1: 1 10 3 11 5 12 7 13
(3) operator=( const slice_array& )
v1: 1 2 3 4 5 6 7 8
v2: 10 11 12 13 14 15
s2: 1 2 3 4
s3: 11 12 13 14
s2 = s3
s2: 11 12 13 14
v1: 11 12 13 14 5 6 7 8
π₯ DEFECT REPORTS π₯
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. history homework but make it slay π
- DR:
LWG 123β Applied to:C++98β Behavior as published: overload (2) was non-const β Correct behavior: made const - DR:
LWG 253β Applied to:C++98β Behavior as published: the copy assignment operator was private β Correct behavior: made public - DR:
LWG 621β Applied to:C++98β Behavior as published: the copy assignment operator was non-const β Correct behavior: made const
source/version/date sign-off tea, bestie: this one's from http://cppreference.com, dated 2024.06.10, and the page is std::slice_...y::operator=(3) β 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