@@ -221,10 +221,26 @@ ParsedFEMFunction<Output>::ParsedFEMFunction (const System & sys,
221
221
template <typename Output>
222
222
inline
223
223
ParsedFEMFunction<Output>::ParsedFEMFunction (const ParsedFEMFunction<Output> & other) :
224
- FEMFunctionBase<Output>(),
225
- _sys(other._sys)
224
+ FEMFunctionBase<Output>(other),
225
+ _sys(other._sys),
226
+ _expression(other._expression),
227
+ _subexpressions(other._subexpressions),
228
+ _n_vars(other._n_vars),
229
+ _n_requested_vars(other._n_requested_vars),
230
+ _n_requested_grad_components(other._n_requested_grad_components),
231
+ _n_requested_hess_components(other._n_requested_hess_components),
232
+ _requested_normals(other._requested_normals),
233
+ _spacetime(other._spacetime),
234
+ _need_var(other._need_var),
235
+ _need_var_grad(other._need_var_grad),
236
+ #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
237
+ _need_var_hess (other._need_var_hess),
238
+ #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES
239
+ variables (other.variables),
240
+ _additional_vars(other._additional_vars),
241
+ _initial_vals(other._initial_vals)
226
242
{
227
- * this = other ;
243
+ this -> reparse (_expression) ;
228
244
}
229
245
230
246
@@ -233,25 +249,12 @@ inline
233
249
ParsedFEMFunction<Output> &
234
250
ParsedFEMFunction<Output>::operator = (const ParsedFEMFunction<Output> & other)
235
251
{
252
+ // We can only be assigned another ParsedFEMFunction defined on the same System
236
253
libmesh_assert (&_sys == &other._sys );
237
254
238
- this ->_expression = other._expression ;
239
- this ->_n_vars = other._n_vars ;
240
- this ->_n_requested_vars = other._n_requested_vars ;
241
- this ->_n_requested_grad_components = other._n_requested_grad_components ;
242
- this ->_n_requested_hess_components = other._n_requested_hess_components ;
243
- this ->_requested_normals = other._requested_normals ;
244
- this ->_need_var = other._need_var ;
245
- this ->_need_var_grad = other._need_var_grad ;
246
- #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
247
- this ->_need_var_hess = other._need_var_hess ;
248
- #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES
249
- this ->_additional_vars = other._additional_vars ;
250
- this ->_initial_vals = other._initial_vals ;
251
-
252
- // parsers can be generated from scratch by reparsing expression
253
- this ->reparse (_expression);
254
-
255
+ // Use copy-and-swap idiom
256
+ ParsedFEMFunction<Output> tmp (other);
257
+ std::swap (tmp, *this );
255
258
return *this ;
256
259
}
257
260
0 commit comments