Skip to content
Snippets Groups Projects
Commit d2f1aa02 authored by Craig Tiller's avatar Craig Tiller
Browse files

Merge branch 'c++lame' of github.com:ctiller/grpc into c++lame

parents 8ebb5443 34e04046
No related branches found
No related tags found
No related merge requests found
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
* *
*/ */
#ifndef GRPC_SUPPORT_MEMORY_H #ifndef GRPC_CORE_LIB_SUPPORT_MEMORY_H
#define GRPC_SUPPORT_MEMORY_H #define GRPC_CORE_LIB_SUPPORT_MEMORY_H
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
...@@ -61,8 +61,8 @@ class DefaultDelete { ...@@ -61,8 +61,8 @@ class DefaultDelete {
void operator()(T* p) { Delete(p); } void operator()(T* p) { Delete(p); }
}; };
template <typename T> template <typename T, typename Deleter = DefaultDelete<T>>
using UniquePtr = std::unique_ptr<T, DefaultDelete<T>>; using UniquePtr = std::unique_ptr<T, Deleter>;
template <typename T, typename... Args> template <typename T, typename... Args>
inline UniquePtr<T> MakeUnique(Args&&... args) { inline UniquePtr<T> MakeUnique(Args&&... args) {
...@@ -71,4 +71,4 @@ inline UniquePtr<T> MakeUnique(Args&&... args) { ...@@ -71,4 +71,4 @@ inline UniquePtr<T> MakeUnique(Args&&... args) {
} // namespace grpc_core } // namespace grpc_core
#endif /* GRPC_SUPPORT_NEW_H */ #endif /* GRPC_CORE_LIB_SUPPORT_MEMORY_H */
...@@ -66,6 +66,19 @@ TEST(MemoryTest, MakeUniqueWithArgTest) { ...@@ -66,6 +66,19 @@ TEST(MemoryTest, MakeUniqueWithArgTest) {
EXPECT_EQ(42, *i); EXPECT_EQ(42, *i);
} }
TEST(MemoryTest, UniquePtrWithCustomDeleter) {
int n = 0;
class IncrementingDeleter {
public:
void operator()(int* p) { ++*p; }
};
{
UniquePtr<int, IncrementingDeleter> p(&n);
EXPECT_EQ(0, n);
}
EXPECT_EQ(1, n);
}
} // namespace testing } // namespace testing
} // namespace grpc_core } // namespace grpc_core
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment