-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Internal Code
-
Labels:
-
Service Arch
It seems like it would be nice to be able to return a ScopeGuard-like type from a function. Eg, construct a guard at the top of a pushState() function to restore it to the then-current state prior to modifying, then return it so that the caller of pushState() will always automatically pop its state modification.
Based on a slack discussion, we decided it would be best to be a separate type to avoid breaking the rule that it is always safe (and preferred!) to use [&] captures with makeGuard (unless you are literally typing return makeGuard([&]{...}) but then you know what you are doing and deserve to win stupid prizes). From the same discussion, it would be safer if the type only supported move construction but not move assignment. This allows the important use case of returning a guard, but disallows silly operations like swapping two guards.