void OnStart()
{
//---
vector v1(10, VectorAssignValues);
Print("v1 = ", v1);
vector v2(10, VectorSetValues);
Print("v2 = ", v2);
}
/* Result
v1 = [1,2,4,8,16,32,64,128,256,512]
v2 = [1,2,4,8,16,32,64,128,256,512]
*/
//+-------------------------------------------------------------------------+
//| 通过赋值运算用数字的幂填充向量 |
//+-------------------------------------------------------------------------+
void VectorAssignValues(vector& v, double initial=1)
{
double value=initial;
for(ulong k=0; k<v.Size(); k++)
{
v[k]=value;
value*=2;
}
}
//+--------------------------------------------------------------------------+
//| 使用Set方法用数字的幂填充向量 |
//+--------------------------------------------------------------------------+
void VectorSetValues(vector& v, double initial=1)
{
double value=initial;
for(ulong k=0; k<v.Size(); k++)
{
v.Set(k, value);
value*=2;
}
}
|