Skip to content

Commit 30b31a1

Browse files
committed
Use a more traditional setter
No need for even a probably-elided copy, so long as we have an rvalue override to avoid the problem of returning a reference-to-this as a temporary. Thanks to Alex for this.
1 parent 9d1fa65 commit 30b31a1

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

include/fe/fe_type.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class FEType
205205
*
206206
* We can't set p_refinement in this argument list without
207207
* conflicting with the \p ro parameter in the InfFE-compatible
208-
* constructor version below, so we use the with_p_refinement API
208+
* constructor version below, so we use the set_p_refinement API
209209
* below to potentially convert an FEType with p-refinement (the
210210
* default) to one without.
211211
*/
@@ -246,7 +246,7 @@ class FEType
246246
*
247247
* We can't set p_refinement in this argument list in a way
248248
* that matches the non-InfFE-enabled constructor version above, so
249-
* we use the with_p_refinement API below to potentially convert an
249+
* we use the set_p_refinement API below to potentially convert an
250250
* FEType with p-refinement (the default) to one without.
251251
*/
252252
FEType(const int o = 1,
@@ -306,11 +306,20 @@ class FEType
306306
* "Fluent API" for constructing a non-default p_refinement, for
307307
* easier compatibility between non-InfFE and InfFE code
308308
*/
309-
FEType with_p_refinement(bool p)
309+
FEType set_p_refinement(bool p) &
310310
{
311-
FEType returnval = *this;
312-
returnval.p_refinement = p;
313-
return returnval;
311+
this->p_refinement = p;
312+
return *this;
313+
}
314+
315+
/**
316+
* Specialization for rvalues so we don't return a dangling
317+
* reference to a temporary.
318+
*/
319+
FEType set_p_refinement(bool p) &&
320+
{
321+
this->p_refinement = p;
322+
return std::move(*this);
314323
}
315324

316325
/**

src/systems/system.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ unsigned int System::add_variable (std::string_view var,
13531353
const bool p_refinement)
13541354
{
13551355
return this->add_variable(var,
1356-
FEType(order, family).with_p_refinement(p_refinement),
1356+
FEType(order, family).set_p_refinement(p_refinement),
13571357
active_subdomains);
13581358
}
13591359

@@ -1375,7 +1375,7 @@ unsigned int System::add_variables (const std::vector<std::string> & vars,
13751375
const bool p_refinement)
13761376
{
13771377
return this->add_variables(vars,
1378-
FEType(order, family).with_p_refinement(p_refinement),
1378+
FEType(order, family).set_p_refinement(p_refinement),
13791379
active_subdomains);
13801380
}
13811381

0 commit comments

Comments
 (0)