Set a subset of the vector.
int SetSubVector( vectorbase & vbSource, int c1 = 0, int nCount = -1 ) int SetSubVector(vectorbase& vbSource, const vector<uint>& vnIndices)
Returns 0 on success or -1 on failure.
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} }
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.
origin.h