mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Optimize final_act for general case where move is not called
This commit is contained in:
parent
df88352c1d
commit
52df7c35e6
@ -78,17 +78,18 @@ template <class F>
|
||||
class final_act
|
||||
{
|
||||
public:
|
||||
explicit final_act(F f) noexcept : f_(std::move(f)), invoke_(true) {}
|
||||
explicit final_act(F f) noexcept : f_(std::move(f)) {}
|
||||
|
||||
final_act(final_act&& other) noexcept : f_(std::move(other.f_)), invoke_(true) { other.invoke_ = false; }
|
||||
final_act(final_act&& other) noexcept : f_(std::move(other.f_)) { other.f_ = NoAction; }
|
||||
final_act(const final_act&) = delete;
|
||||
final_act& operator=(const final_act&) = delete;
|
||||
|
||||
~final_act() noexcept { if (invoke_) f_(); }
|
||||
~final_act() noexcept { f_(); }
|
||||
|
||||
private:
|
||||
F f_;
|
||||
bool invoke_;
|
||||
|
||||
static void NoAction(){}
|
||||
};
|
||||
|
||||
// finally() - convenience function to generate a final_act
|
||||
|
Loading…
Reference in New Issue
Block a user