Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
scoped_destructor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Roc authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_core/scoped_destructor.h
10 //! @brief Scoped destructor.
11 
12 #ifndef ROC_CORE_SCOPED_DESTRUCTOR_H_
13 #define ROC_CORE_SCOPED_DESTRUCTOR_H_
14 
15 #include "roc_core/noncopyable.h"
16 
17 namespace roc {
18 namespace core {
19 
20 //! Destroys the object via custom deleter.
21 template <class T, void (*Func)(T)> class ScopedDestructor : public NonCopyable<> {
22 public:
23  //! Initialize.
24  explicit ScopedDestructor(T obj)
25  : obj_(obj) {
26  }
27 
28  //! Destroy.
30  Func(obj_);
31  }
32 
33 private:
34  T obj_;
35 };
36 
37 } // namespace core
38 } // namespace roc
39 
40 #endif // ROC_CORE_SCOPED_DESTRUCTOR_H_
Root namespace.
ScopedDestructor(T obj)
Initialize.
Base class for non-copyable objects.
Definition: noncopyable.h:23
Destroys the object via custom deleter.
Non-copyable object.