valarray::cshift

定期按位置指定数量的将 valarray 的所有元素。

valarray<Type> cshift( 
   int _Count 
) const;

参数

  • _Count
    排列元素的数量是向前移动。

返回值

新 valarray 其中所有元素都移动的 _Count 位置定期朝着前面 valarray,按照与其在 valarray 操作数的位置。

备注

正数值 _Count 移动元素定期离开的 _Count 位置。

负值 _Count 移动元素周期正确的位置。_Count

示例

// valarray_cshift.cpp
// compile with: /EHsc

#include <valarray>
#include <iostream>

int main()
{
    using namespace std;
    int i;

    valarray<int> va1(10), va2(10);
    for (i = 0; i < 10; i+=1)
        va1[i] = i;
    for (i = 0; i < 10; i+=1)
        va2[i] = 10 - i;

    cout << "The operand valarray va1 is: (";
    for (i = 0; i < 10; i++)
        cout << " " << va1[i];
    cout << ")" << endl;

    // A positive parameter shifts elements right
    va1 = va1.cshift(4);
    cout << "The cyclically shifted valarray va1 is:\nva1.cshift (4) = (";
    for (i = 0; i < 10; i++)
        cout << " " << va1[i];
    cout << ")" << endl;

    cout << "The operand valarray va2 is: (";
    for (i = 0; i < 10; i++)
        cout << " " << va2[i];
    cout << ")" << endl;

    // A negative parameter shifts elements left
    va2 = va2.cshift(-4);
    cout << "The cyclically shifted valarray va2 is:\nva2.shift (-4) = (";
    for (i = 0; i < 10; i++)
        cout << " " << va2[i];
    cout << ")" << endl;
}
  

要求

Header: <valarray>

命名空间: std

请参见

参考

valarray 类