Vector Destructor Iterator

The so-called “vector destructor iterator” is known internally by the identifier __vec_dtor (at global scope), with the following compiler-generated code:

inline void __stdcall __vec_dtor (
    void *__t,
    unsigned __s,
    int __n,
    void (__thiscall *__f) (void *))
    __t = (char *) __t + __s * __n;
    while (-- __n >= 0) {
        __t = (char *) __t - __s;
        (*__f) (__t);

Given __n objects each of size __s in an array at address __t, and a destructor at address __f, the iterator calls the destructor once for each object in the array, in reverse order.


The following fragment induces the compiler to generate a vector constructor iterator:

struct Test
    ~Test (void);

void test (Test *t)
    delete [] t;