Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
23.vector.stdcxx-494.cpp
Go to the documentation of this file.
1
29#include <cassert> // for assert()
30#include <cstddef> // for size_t
31#include <memory> // for allocator
32#include <vector> // for vector
33
34
35template <class T>
36struct EmptyAllocator: std::allocator<T>
37{
38 template <class U>
39 struct rebind { typedef EmptyAllocator<U> other; };
40
43 : std::allocator<T>(rhs) { }
44
45 template <class U>
47 : std::allocator<T>(rhs) { }
48
49 void* operator new (std::size_t) { return 0; }
50 void operator delete (void*) { }
51};
52
53
54int main ()
55{
56 // verify that vector doesn't derive from allocator
57 // (otherwise the replacement operator new and delete
58 // are in conflict)
59
60 typedef std::vector<int, EmptyAllocator<int> > EmptyVector;
61
62 delete new EmptyVector;
63
64 // verifies empty base optimization
65 assert (sizeof (std::vector<int>) == sizeof (EmptyVector));
66
67 // assert that the size of vector is exactly 3 pointers
68 assert (sizeof (std::vector<int>) == 3 * sizeof (int*));
69
70 return 0;
71}
#define T
Definition 17.names.cpp:163
#define rhs
Definition 17.names.cpp:536
int main()
#define assert(expr)
Definition _cassert.h:40
Definition json.h:5363
EmptyAllocator(const EmptyAllocator &rhs)
EmptyAllocator(const EmptyAllocator< U > &rhs)