Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
23.vector.stdcxx-1037.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
34template <typename T>
35struct Alloc : std::allocator<T>
36{
37 Alloc (int i) : i_ (i) { }
38
39 template <typename U>
40 struct rebind {
41 typedef Alloc<U> other;
42 };
43
44 template <typename U>
45 Alloc (const Alloc<U>& other)
46 : std::allocator<T>(other), i_ (other.i_) { }
47
48 template <typename U>
49 Alloc& operator= (const Alloc<U>& other)
50 {
51 std::allocator<T>::operator= (other);
52 i_ = other.i_;
53 return *this;
54 }
55
56 int i_;
57};
58
59template <typename T>
60bool operator== (const Alloc<T>& a1, const Alloc<T>& a2)
61{
62 return a1.i_ == a2.i_;
63}
64
65int main ()
66{
67 std::vector<int, Alloc<int> > v1 (Alloc<int> (1));
68 v1.push_back (1);
69 assert (1 == v1.size () && 1 == v1.front ());
70
71 std::vector<int, Alloc<int> > v2( Alloc<int> (2));
72 v2.push_back (2);
73 assert (1 == v2.size () && 2 == v2.front ());
74
75 v1.swap (v2);
76
77 assert (1 == v1.size () && 2 == v1.front ());
78 assert (1 == v2.size () && 1 == v2.front ());
79
80 return 0;
81}
#define i
Definition 17.names.cpp:126
#define T
Definition 17.names.cpp:163
#define i_
Definition 17.names.cpp:180
#define v2
Definition 17.names.cpp:271
#define a2
Definition 17.names.cpp:251
#define a1
Definition 17.names.cpp:225
#define v1
Definition 17.names.cpp:245
bool operator==(const Alloc< T > &a1, const Alloc< T > &a2)
#define assert(expr)
Definition _cassert.h:40
Alloc(const Alloc< U > &other)
Definition json.h:5363