Swap
Échange les tampons entre matrices, vecteurs et tableaux dynamiques du même type.
bool matrix<T>::Swap(
matrix<T> &mat
);
bool matrix<T>::Swap(
vector<T> &vec
);
bool matrix<T>::Swap(
T &array[]
);
bool vector<T>::Swap(
vector<T> &vec
);
bool vector<T>::Swap(
matrix<T> &mat
);
bool vector<T>::Swap(
T &array[]
);
|
Paramètres
mat, vec ou array
[in] La matrice, le vecteur ou le tableau dynamique dont le tampon associé doit être échangé.
Valeur de Retour
Note
Exemple:
template<typename T>
bool Test(void)
{
matrix<T> a(3,5);
matrix<T> b(5,4);
vector<T> v(10);
if(!a.Swap(b) || a.Rows()!=5 || a.Cols()!=4 || b.Rows()!=3 || b.Cols()!=5)
return(false);
if(!a.Swap(v) || v.Size()!=20 || a.Rows()!=1 || a.Cols()!=10)
return(false);
//--- exemple négatif : tableau non dynamique
T arr1D[10];
if(a.Swap(arr1D) || GetLastError()!=ERR_INVALID_ARRAY)
return(false);
if(v.Swap(arr1D))
return(false);
//--- exemple négatif : taille de tableau incorrecte
T arr2D[][3];
ArrayResize(arr2D,5);
v.Resize(15);
if(a.Swap(arr2D) || !v.Swap(arr2D))
return(false);
return(true);
}
//+------------------------------------------------------------------+
//| Fonction de démarrage du script |
//+------------------------------------------------------------------+
int OnStart(void)
{
bool res=true;
res&=Test<double>();
res&=Test<float>();
res&=Test<complex>();
res&=Test<complexf>();
Print(res ? "passed" : "failed");
return(res ? 0 : -1);
}
|
Voir aussi
Assign