OpenMS
RAIICleanup.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Chris Bielow $
6 // $Authors: Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 #include <functional>
12 
13 namespace OpenMS
14 {
23  {
24  public:
26  RAIICleanup() = delete;
27 
29  RAIICleanup(std::function<void()> l)
30  : l_(l)
31  {}
32 
34  {
35  l_();
36  }
37 
38  private:
39  std::function<void()> l_;
40  };
41 
42 } // namespace OPENMS
43 
Exception-safe way of executing arbitrary code at the end of a scope.
Definition: RAIICleanup.h:23
RAIICleanup(std::function< void()> l)
pass in any lambda you like which does the cleanup at the end
Definition: RAIICleanup.h:29
RAIICleanup()=delete
no default CTor; we need a lambda
std::function< void()> l_
called upon destruction
Definition: RAIICleanup.h:39
~RAIICleanup()
Definition: RAIICleanup.h:33
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22