Swap

Intercambia los búferes entre matrices, vectores y arrays dinámicos del mismo tipo.

bool matrix<T>::Swap(
  matrix<T>  &mat     // matriz a intercambiar
   );
 
bool matrix<T>::Swap(
  vector<T>  &vec     // vector a intercambiar
   );
 
bool matrix<T>::Swap(
  T          &array[] // array a intercambiar
   );
 
bool vector<T>::Swap(
  vector<T>  &vec     // vector a intercambiar
   );
 
bool vector<T>::Swap(
  matrix<T>  &mat     // matriz a intercambiar
   );
 
bool vector<T>::Swap(
  T          &array[] // array a intercambiar
   );
 

Parámetros

mat, vec o array

[in]  La matriz, el vector o el array dinámico cuyo búfer asociado se debe intercambiar.

Valor devuelto

Devuelve true si la operación se realiza correctamente; en caso contrario, false.

Nota

El tamaño del array debe ser múltiplo del tamaño de la matriz o del vector. El tamaño del vector debe ser múltiplo del tamaño de la matriz.

Ejemplo:

template<typename T>
bool Test(void)
  {
   matrix<Ta(3,5);
   matrix<Tb(5,4);
   vector<Tv(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);
 
//--- ejemplo negativo: array no dinámico
   T arr1D[10];
   if(a.Swap(arr1D) || GetLastError()!=ERR_INVALID_ARRAY)
      return(false);
   if(v.Swap(arr1D))
      return(false);
 
//--- ejemplo negativo: tamaño de array incorrecto
   T arr2D[][3];
   ArrayResize(arr2D,5);
   v.Resize(15);
   if(a.Swap(arr2D) || !v.Swap(arr2D))
      return(false);
 
   return(true);
  }
//+------------------------------------------------------------------+
//| Función de inicio del 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);
  }

Véase también

Assign