Design #1682
swap for new classes
Description
The description at cppreference
strongly suggests that user-defined classes should be accompanied by their own swap
functions:
see https://en.cppreference.com/w/cpp/algorithm/swap
We should review all classes in CoCoALib in light of this.
This is really a matter of efficiency (rather than correctness).
Related issues
History
#1 Updated by John Abbott almost 2 years ago
I presented the template class factorization
to my students, and asked whether it automatically had a "smart" swap
capability.
Investigating led us to the page on the cppreference web-site.
I have not yet tested to see whether swapping factorization
objects is costly (& exc safe) or not.
#2 Updated by John Abbott over 1 year ago
- Status changed from New to In Progress
- % Done changed from 0 to 10
There is an efficient swap
function for RingElem
.
There is also a virtual mem fn RingBase::mySwap
which is different from swap
.mySwap
with its current interface has to be virtual because it receives as input
copies of the raw pointers to the values. Instead it should receive references
to the pointers, this in turn requires that the accessor functions myRawPtr
return
references (which indeed they do). An alternative would be to access the data memmyValuePtr
directly (but that is poor encapsulation).
mySwap
is called surprisingly often. Perhaps some of these can be changed to
calls to std::swap
?
#3 Updated by John Abbott over 1 year ago
- Related to Design #1685: RingBase::mySwap needed? added
#4 Updated by John Abbott 2 months ago
- Target version changed from CoCoALib-0.99850 to CoCoALib-0.99900