CppCommon  1.0.4.1
C++ Common Library
resource.h
Go to the documentation of this file.
1 
9 #ifndef CPPCOMMON_UTILITY_RESOURCE_H
10 #define CPPCOMMON_UTILITY_RESOURCE_H
11 
12 #include <memory>
13 
14 namespace CppCommon {
15 
17 
42 template <typename T, typename TCleaner>
43 auto resource(T handle, TCleaner cleaner)
44 {
45  return std::unique_ptr<typename std::remove_pointer<T>::type, TCleaner>(handle, cleaner);
46 }
47 
49 
53 template <typename TCleaner>
54 auto resource(void* handle, TCleaner cleaner)
55 {
56  return std::unique_ptr<void, TCleaner>(handle, cleaner);
57 }
58 
60 
63 template <typename TCleaner>
64 auto resource(TCleaner cleaner)
65 {
66  return std::unique_ptr<void, TCleaner>(&cleaner, cleaner);
67 }
68 
69 } // namespace CppCommon
70 
71 #endif // CPPCOMMON_UTILITY_RESOURCE_H
C++ Common project definitions.
Definition: token_bucket.h:15
auto resource(T handle, TCleaner cleaner)
Resource smart cleaner pattern.
Definition: resource.h:43