@@ -214,9 +214,18 @@ ParsedFunction<Output,OutputGradient>::ParsedFunction (const std::string & expre
214
214
template <typename Output, typename OutputGradient>
215
215
inline
216
216
ParsedFunction<Output,OutputGradient>::ParsedFunction (const ParsedFunction<Output,OutputGradient> & other) :
217
- FunctionBase<Output>()
217
+ FunctionBase<Output>(other),
218
+ _expression(other._expression),
219
+ _subexpressions(other._subexpressions),
220
+ _spacetime(other._spacetime),
221
+ _valid_derivatives(other._valid_derivatives),
222
+ variables(other.variables),
223
+ _additional_vars(other._additional_vars),
224
+ _initial_vals(other._initial_vals)
218
225
{
219
- *this = other;
226
+ // parsers can be generated from scratch by reparsing expression
227
+ this ->reparse (this ->_expression );
228
+ this ->_initialized = true ;
220
229
}
221
230
222
231
@@ -226,17 +235,9 @@ inline
226
235
ParsedFunction<Output,OutputGradient> &
227
236
ParsedFunction<Output,OutputGradient>::operator = (const ParsedFunction<Output,OutputGradient> & other)
228
237
{
229
- this ->_master = other._master ;
230
- this ->_expression = other._expression ;
231
- this ->_spacetime = other._spacetime ;
232
- this ->_valid_derivatives = other._valid_derivatives ;
233
- this ->_additional_vars = other._additional_vars ;
234
- this ->_initial_vals = other._initial_vals ;
235
-
236
- // parsers can be generated from scratch by reparsing expression
237
- this ->reparse (this ->_expression );
238
- this ->_initialized = true ;
239
-
238
+ // Use copy-and-swap idiom
239
+ ParsedFunction<Output,OutputGradient> tmp (other);
240
+ std::swap (tmp, *this );
240
241
return *this ;
241
242
}
242
243
0 commit comments