Skip to content

Commit ca338c6

Browse files
committed
Add DirichletBoundary copy assignment operator.
Also add defaulted destructor, move constructor, and assignment operators. As far as I understand it, you can std::swap a class T which is both move-constructible and move-assignable, but I'm not sure if this is guaranteed to work in C++11 or if some later standard is required. If it works for our "min" compilers, then I'm happy. https://en.cppreference.com/w/cpp/algorithm/swap
1 parent f8ee7a7 commit ca338c6

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

include/base/dirichlet_boundaries.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,17 @@ class DirichletBoundary
160160
VariableIndexing type = SYSTEM_VARIABLE_ORDER);
161161

162162
/**
163-
* Copy constructor. Deep copies (clones) functors; shallow copies
164-
* any System reference
163+
* Copy assignment/constructor. Deep copies (clones) functors;
164+
* shallow copies any System reference
165165
*/
166166
DirichletBoundary (const DirichletBoundary & dirichlet_in);
167+
DirichletBoundary & operator= (const DirichletBoundary &);
168+
169+
/**
170+
* This class is default move-assignable and move-constructible.
171+
*/
172+
DirichletBoundary (DirichletBoundary &&) = default;
173+
DirichletBoundary & operator= (DirichletBoundary &&) = default;
167174

168175
/**
169176
* Standard destructor

src/base/dirichlet_boundary.C

+10-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,16 @@ DirichletBoundary(const DirichletBoundary & d_in) :
196196
}
197197

198198

199-
DirichletBoundary::~DirichletBoundary () {}
199+
DirichletBoundary & DirichletBoundary::operator= (const DirichletBoundary & rhs)
200+
{
201+
// Implementation in terms of the copy constructor to avoid code duplication.
202+
DirichletBoundary tmp(rhs);
203+
std::swap(tmp, *this); // class must be "MoveAssignable" and "MoveConstructible" for std::swap to work.
204+
return *this;
205+
}
206+
207+
208+
DirichletBoundary::~DirichletBoundary () = default;
200209

201210
} // namespace libMesh
202211

0 commit comments

Comments
 (0)