Capacity() const
EnsureCapacity(CTBint i_cap)
IncreaseCapacity(CTBint i_cap)
EnsureCapacity()
, but the capacity is at least increased by a factor, typically 2. This method is usually called in flexible containers when additional objects are stored. The increase by a factor ensures that at most log2(size) reallocations have to be performed and that on average an object is only copied once. TrimCapacity()
a Capacity() method allows to inquire the capacity and an EnsureCapacty() method allows to increase the capacity.
new
'ed copy of the object and has the following signature and typical implementation: class base { public: virtual base* Clone() const { return new base(*this) }; }; class foo : public base { public: virtual base* Clone() const { return new foo(*this) }; };
See also CTBclone
.
int
value, which is 0 if both objects are equal, a positive number if the lhs (first) argument is larger than the rhs (second) argument, and a negative number if the lhs (first) argument is smaller than the rhs (second) argument: return value | condition |
0 | lhs == rhs |
> 0 | lhs > rhs |
< 0 | lhs < rhs |
CTBcompareFunc
and CTBcompareOper
, and in Compare
methods.
Using compare functions can improve performance in cases where often a test on equality of two objects is paired with a test on relative order, as in binary tree search algorithm (e.g. see implementation of CTBmap
).
Grab()
methods.
class foo { public: foo(); // default constructor foo(const foo& rhs); // copy constructor foo(foo& rhs, bool b_grab); // grab constructor ... }; foo::foo(foo& rhs, bool ) { ... }
See also CTBgrab
.
CTBretObj
.
class base { ... }; class foo : public base { ...} ; base* p = new foo(); ... delete p;
class base { ... virtual ~base(); ... };
delete
operator.
All non-trivial classes which are expected to be base classes should have a virtual destructor. A typical guide line is `if there is any virtual method, declare the destructor also as virtual'.