Part of Allocarors

xiaoxiao2021-03-06  50

#include

#include

Using namespace std;

Template

TypeName Allocator = Allocator >

Class Coll {

PUBLIC:

Explicit Coll (Const Allocator & A = Allocator ())

: Alloc (a), Sizenum (0), root (null) {}

Explicit Coll (const size_t size,

Const Ty & Val,

Const Allocator & A = Allocator ())

: Alloc (a), Sizenum (Size), Root (NULL)

{

Root = alloc.allocate (sizenum);

Uninitialized_fill_n (root, sizenum, val);

}

COLL (Const Coll & C)

: Alloc (c.alloc), Sizenum (C.Sizenum), Root (NULL)

{

Root = alloc.allocate (sizenum);

Uninitialized_copy (c.Root, C.Root Sizenum,

Root);

}

Virtual ~ COLL ()

{

For (size_t i = 0; i

{

Alloc.destroy (& root [i]);

}

Alloc.deallocate (root, sizenum);

}

Const Coll & Operator = (Const Coll & C)

{

IF (this == & c)

RETURN * THIS;

IF (root! = null)

{

For (size_t i = 0; i

{

Alloc.destroy (& root [i]);

}

Alloc.deallocate (root, sizenum);

}

Alloc = c.alloc;

Sizenum = C.Sizenum;

Root = alloc.allocate (sizenum);

Uninitialized_copy (c.Root, C.Root Sizenum,

Root);

Return C;

}

Virtual Void Output (Ostream & Strem) Const

{

For (size_t i = 0; i

{

StREM << root [i] << "

}

}

Private:

Allocator alloc;

SIZE_T Sizenum;

Ty * root;

}

Int main (void)

{

Coll C (10,100);

Coll a (c);

Coll B;

B = a;

B.output (cout);

cin.get ();

Return 0;

}

转载请注明原文地址:https://www.9cbs.com/read-80455.html

New Post(0)