Y
yonil
I hope this is the correct group for this...
I'm currently implementing the TR1 associative containers according to
specification found in
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1745.pdf.
Now I'm not sure how to interpret a requirement relating to exception
safety. It says in 6.3.1.1:
"For unordered associative containers, if an exception is thrown by any
operation other than the container's hash function from within an
insert() function inserting a single element, the insert() function has
no effect.".
Now, in the "range insertion" method: template <class InputIterator>
void insert(InputIterator first, InputIterator last)
the implementation inserts the elements one at a time, the question is
what to do if a single insert() throws an exception. I didn't
understand whether it's supposed to erase anything it inserted so far
(and btw, should it be erased in the reverse order to the insertions?),
or whether to simply return regardless of how many elements were
inserted.
I looked in the implementation of MSVC STL containers, and the code for
the equivalent function in <set> doesn't unwind the insertions. On the
other hand, inserting a range to a vector or a list seems to be a
transactional operation.
Also, if it is required to be transactional in the TR1 associative
containers, then for input iterators I'll have to make a temporary copy
of all the inserted values (e.g. a vector/stack) (right?), though for
forward or stronger categories there's no problem and I can simply
invoke erase(first, current) and rethrow.
I'm also wondering what happens if the erase operations throw? does
that mean the original exception is lost? also, does it mean you have
to do the range insert on a temporary copy of the unordered_set? I mean
otherwise the insertion won't be transactional in such case. I'm kinda
lost here.
I'm currently implementing the TR1 associative containers according to
specification found in
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1745.pdf.
Now I'm not sure how to interpret a requirement relating to exception
safety. It says in 6.3.1.1:
"For unordered associative containers, if an exception is thrown by any
operation other than the container's hash function from within an
insert() function inserting a single element, the insert() function has
no effect.".
Now, in the "range insertion" method: template <class InputIterator>
void insert(InputIterator first, InputIterator last)
the implementation inserts the elements one at a time, the question is
what to do if a single insert() throws an exception. I didn't
understand whether it's supposed to erase anything it inserted so far
(and btw, should it be erased in the reverse order to the insertions?),
or whether to simply return regardless of how many elements were
inserted.
I looked in the implementation of MSVC STL containers, and the code for
the equivalent function in <set> doesn't unwind the insertions. On the
other hand, inserting a range to a vector or a list seems to be a
transactional operation.
Also, if it is required to be transactional in the TR1 associative
containers, then for input iterators I'll have to make a temporary copy
of all the inserted values (e.g. a vector/stack) (right?), though for
forward or stronger categories there's no problem and I can simply
invoke erase(first, current) and rethrow.
I'm also wondering what happens if the erase operations throw? does
that mean the original exception is lost? also, does it mean you have
to do the range insert on a temporary copy of the unordered_set? I mean
otherwise the insertion won't be transactional in such case. I'm kinda
lost here.