Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- struct xyz {
- // empty constructor: should leave 'v' uninitialized!
- xyz() { }
- xyz(const xyz& o): v(o.v) { }
- xyz& operator=(const xyz& o) { v=o.v; return *this; }
- int v;
- };
- template <typename T>
- class uninitialized_allocator : public std::allocator< T > {
- private:
- bool* should_init;
- public:
- //provide the required no-throw constructors / destructors:
- uninitialized_allocator() throw() : std::allocator<xyz>() { };
- uninitialized_allocator(const uninitialized_allocator<T>& rhs) throw() : std::allocator<T>(rhs) { };
- template <typename U>
- uninitialized_allocator(const std::allocator<U>& rhs) throw() : std::allocator<T>(rhs) { };
- ~uninitialized_allocator() throw() { };
- //import the required typedefs:
- typedef typename std::allocator<T>::value_type value_type;
- typedef typename std::allocator<T>::pointer pointer;
- typedef typename std::allocator<T>::reference reference;
- typedef typename std::allocator<T>::const_pointer const_pointer;
- typedef typename std::allocator<T>::const_reference const_reference;
- typedef typename std::allocator<T>::size_type size_type;
- typedef typename std::allocator<T>::difference_type difference_type;
- //redefine the construct function (hiding the base-class version):
- void construct( pointer p, const_reference o) {
- };
- };
- typedef std::vector<xyz, uninitialized_allocator<xyz> > myvec_t;
- extern myvec_t test() {
- return myvec_t(1024);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement