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

pull/10676/head
Craig Tiller 8 years ago
commit d2f1aa0275
  1. 10
      src/core/lib/support/memory.h
  2. 13
      test/core/support/memory_test.cc

@ -31,8 +31,8 @@
*
*/
#ifndef GRPC_SUPPORT_MEMORY_H
#define GRPC_SUPPORT_MEMORY_H
#ifndef GRPC_CORE_LIB_SUPPORT_MEMORY_H
#define GRPC_CORE_LIB_SUPPORT_MEMORY_H
#include <grpc/support/alloc.h>
@ -61,8 +61,8 @@ class DefaultDelete {
void operator()(T* p) { Delete(p); }
};
template <typename T>
using UniquePtr = std::unique_ptr<T, DefaultDelete<T>>;
template <typename T, typename Deleter = DefaultDelete<T>>
using UniquePtr = std::unique_ptr<T, Deleter>;
template <typename T, typename... Args>
inline UniquePtr<T> MakeUnique(Args&&... args) {
@ -71,4 +71,4 @@ inline UniquePtr<T> MakeUnique(Args&&... args) {
} // namespace grpc_core
#endif /* GRPC_SUPPORT_NEW_H */
#endif /* GRPC_CORE_LIB_SUPPORT_MEMORY_H */

@ -66,6 +66,19 @@ TEST(MemoryTest, MakeUniqueWithArgTest) {
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 grpc_core

Loading…
Cancel
Save