efficient swap operation for vector and matrix classes

This commit is contained in:
2021-06-29 14:39:04 +02:00
parent 3288e51fba
commit 9d0249cdc4
5 changed files with 57 additions and 0 deletions

11
vec.h
View File

@@ -383,6 +383,17 @@ public:
for(int i=0; i<nn; ++i) v[i] = _F(v[i]);
return *this;
};
void swap(NRVec &rhs) //more efficient swap than via tmp and constructors and operator=
{
int tmpnn=nn; nn=rhs.nn; rhs.nn=tmpnn;
T *tmpv=v; v=rhs.v; rhs.v=tmpv;
int *tmpcount=count; count=rhs.count; rhs.count=tmpcount;
#ifdef CUDALA
GPUID tmplocation=location; location=rhs.location; rhs.location=tmplocation;
#endif
}
};