2.2.3.19.37 vectorbase::SetSubVector

Description

Set a subset of the vector.

Syntax

int SetSubVector( vectorbase & vbSource, int c1 = 0, int nCount = -1 )

int SetSubVector(vectorbase& vbSource, const vector<uint>& vnIndices)

Parameters

vbSource
[input] vectorbase object containing the subset to be set
c1
[input] Begining element index in the target vector, default is 0 (0-based)
nCount
[input] Number of elements being set. Default -1 means no effect. Must be within range [1, size of vbSource] if specified.
vnIndices
[input] vector of indices in the target vector to be set.

Return

Returns 0 on success or -1 on failure.

Examples

EX1

void vectorbase_SetSubVector_ex1()
{
    vector vec1 = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9};
    vector vec2 = {1.1, 2.1, 3.1};
    vec1.SetSubVector(vec2, 3);
   	for (int ii = 0; ii < vec1.GetSize(); ii++)
    	printf("%.1f ",vec1[ii]);
   	printf("\n");
    // Result:
    //        vec1 = {0.1, 0.2, 0.3, 1.1, 2.1, 3.1, 0.7, 0.8, 0.9}

    vec2.SetSubVector(vec1);
  	for (ii = 0; ii < vec2.GetSize(); ii++)
    	printf("%.1f ",vec2[ii]);
    // Result:
    //        vec2 = {0.1, 0.2, 0.3}
    //        Size of vec2 does not change even though vec1 was larger
}

EX2

void vectorbase_SetSubVector_ex2()
{
    vector<int> vA = {0, 1, 2, 3};
    vector<uint> vnIndices = {0, 2};
    vector<int> vSource = {4, 5};
    vA.SetSubVector( vSource, vnIndices );  // vA = {4, 1, 5, 3}
}

Remark

Set a subset of this vector using specified 0-based element indices. The source and target vectors can have different types and different dimensions but the target vector is not resized even if the source vector is larger than the target. The different types must be numeric types, for example, int, double, float, uint.

See Also

Vectorbase::GetSubVector

Header to Include

origin.h