Lists
atomic::list is implemented as a doubly linked list of nodes, just like std::list would be implemented. When an item is inserted into the list, the node containing the item is logged on the transaction stack. When an item is deleted, it is removed from the data structure and stored on the transaction stack. To roll back a delete, the left and right pointers point to live nodes, giving the correct place in the list to insert the node.
There is no possibility of an exception being thrown because roll back only requires pointer manipulation, not any memory allocation. To roll back an insertion, the list node is removed and deleted (which will not throw). Figure 1 shows how list operations can be rolled back.
Trees
The tree-based containers (atomic::map and the like) are based upon an implementation of red-black trees (a standard technique for balancing trees). When an item is inserted into the data structure, it is logged on the transaction stack. When an item is deleted, it is removed from the data structure and stored on the transaction stack.
Rolling back a deletion is tricky because the object must be inserted in the correct position in the tree. You cannot simply call insert() to insert the node back into the data structure because the comparators might throw, and the nodes might end up in a different order than the original. So the deleted node stores the next node in the data structure. When the deletion is rolled back, the node is reinserted immediately before the next node in the data structure. There are a few cases to consider, but the procedure can be performed reliably. Figure 2 shows how tree operations are rolled back (ignoring tree balancing).
With red-back trees, the tree-balancing algorithms must be called after an insertion or a deletion, but these only perform pointer manipulation and will not throw exceptions.