std::valarray<T>:: shift
From cppreference.net
C++
Numerics library
| Common mathematical functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical special functions (C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical constants (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic linear algebra algorithms (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Data-parallel types (SIMD) (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Floating-point environment (C++11) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Complex numbers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numeric array (
valarray
)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Pseudo-random number generation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Bit manipulation (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Saturation arithmetic (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Factor operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Interpolations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Generic numeric operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C-style checked integer arithmetic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
valarray
<
T
>
shift
(
int
count
)
const
;
|
||
返回一个大小相同的新 valarray,其元素位置被移动了 count 个元素。每个元素的新位置为 i−count ,其中 i 是原位置。被移入元素的值是 T ( ) 。
目录 |
参数
| count | - | 元素需要移动的位置数量 |
返回值
结果为一个元素已移位后的 valarray。
注释
该函数可以实现为返回类型不同于 std::valarray 的情况。此时,替换类型需具备以下特性:
-
- 提供了 const 成员函数的所有 std::valarray 。
- 可以从替换类型构造 std::valarray 、 std::slice_array 、 std::gslice_array 、 std::mask_array 和 std::indirect_array 。
- 对于每个接受 const std:: valarray < T > & 的函数(除 begin() 和 end() 外 (C++11 起) ),应添加接受替换类型的相同函数;
- 对于每个接受两个 const std:: valarray < T > & 参数的函数,应添加接受 const std:: valarray < T > & 与替换类型所有组合的相同函数。
- 返回类型不会在最深嵌套的参数类型基础上增加超过两层的模板嵌套。
示例
运行此代码
#include <iostream> #include <valarray> int main() { std::valarray<int> v{1, 2, 3, 4, 5, 6, 7, 8}; for (auto const& val : v) std::cout << val << ' '; std::cout << '\n'; std::valarray<int> v2 = v.shift(2); for (auto const& val : v2) std::cout << val << ' '; std::cout << '\n'; }
输出:
1 2 3 4 5 6 7 8 3 4 5 6 7 8 0 0
参见
|
对 valarray 元素进行循环移位
(公开成员函数) |