typedef void value_type;
typedef void* pointer;
typedef const void* const_pointer;
+
+ StlAllocator() : alloc_(nullptr) { }
+ explicit StlAllocator(Alloc* alloc) : alloc_(alloc) { }
+
+ Alloc* alloc() const {
+ return alloc_;
+ }
+
template <class U> struct rebind {
typedef StlAllocator<Alloc, U> other;
};
+
+ bool operator!=(const StlAllocator<Alloc, void>& other) const {
+ return alloc_ != other.alloc_;
+ }
+
+ bool operator==(const StlAllocator<Alloc, void>& other) const {
+ return alloc_ == other.alloc_;
+ }
+
+ private:
+ Alloc* alloc_;
};
template <class Alloc, class T>
>::value));
}
+TEST(StlAllocator, void_allocator) {
+ typedef StlAllocator<SysArena, void> void_allocator;
+ SysArena arena;
+ void_allocator valloc(&arena);
+
+ typedef void_allocator::rebind<int>::other int_allocator;
+ int_allocator ialloc(valloc);
+
+ auto i = std::allocate_shared<int>(ialloc, 10);
+ ASSERT_NE(nullptr, i.get());
+ EXPECT_EQ(10, *i);
+ i.reset();
+ ASSERT_EQ(nullptr, i.get());
+}
+
int main(int argc, char **argv) {
FLAGS_logtostderr = true;
google::InitGoogleLogging(argv[0]);