- void Append(value_type *obj)
- {
- wxASSERT(m_size < m_capacity);
- m_objects[m_size] = obj;
+#if wxUSE_EXCEPTIONS
+ try
+ {
+#endif
+ // use placement new to initialize new object in preallocated place
+ // in m_values and store 'v' in it:
+ void* const place = m_values + idx;
+ new(place) value_type(v);
+#if wxUSE_EXCEPTIONS
+ }
+ catch ( ... )
+ {
+ // if the ctor threw an exception, we need to move all the elements
+ // back to their original positions in m_values
+ if ( after > 0 )
+ {
+ memmove(m_values + idx,
+ m_values + idx + 1,
+ after * sizeof(value_type));
+ }
+
+ throw; // rethrow the exception
+ }
+#endif // wxUSE_EXCEPTIONS
+
+ // increment m_size only if ctor didn't throw -- if it did, we'll be
+ // left with m_values larger than necessary, but number of elements will
+ // be the same