473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Requirements of TR1 associative containers

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/wg...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 <setdoesn'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.

Oct 8 '06 #1
1 1779

yonil wrote:
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/wg...2005/n1745.pdf.
comp.std.c++ is the better group.
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.
That's an implementation detail. You're not bound by the interface
requirement
of the (public) single-element insert functions just because you reuse
that same
insert function internally.
The question is what to do if a single insert() throws an exception.
There's not a lot you can do? Just pass on the exception. There is no
requirement
to do rollback. Of course, the container should be in some sane state
(must be
able to be destroyed).
I didn't understand whether it's supposed to erase anything it inserted so far
Not AFAIK; I think vector and set have exactly the same restrictions.
I looked in the implementation of MSVC STL containers, and the code for
the equivalent function in <setdoesn't unwind the insertions.
Considering Dinkuware knows the standard a whole lot better than I do,
*and*
that they agree with me, I'd say we're both right then ;)
On the other hand, inserting a range to a vector or a list seems to be a
transactional operation.
It's definitely allowed, if you can do so.
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.
Are you confusing source iterator ranges and the associative iterator
ranges?
You know your own iterators. The source iterators are unspecified, but
once you
throw you're not using those to rollback.
I'm also wondering what happens if the erase operations throw? does
that mean the original exception is lost?
Yes, it would imply that, which is why it can't (again, AFAIK). The
assumption is
of course that the value_type dtor doesn't throw.
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.
No; even if you needed transactional behavior you could just keep track
of the
iterators to erase if needed. But check in csc++ to be sure.

Regards,
Michiel Salters

Oct 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ney André de Mello Zunino | last post by:
Hello. A non-modifying algorithm I implemented uses two associative containers from STL: set and map. The elements on those containers are supposed to refer to actual elements which lie on...
1
by: Neil Zanella | last post by:
Hello, I would like to know what the exact requirements are for classes that use associative containers in terms of which overloaded operators and constructors they must provide. For instance,...
1
by: Dave | last post by:
Hello all, Why is the term "associative" containter used to describe std::set<>, std::map<>, std::multiset<> and std::multimap<>? I always had the impression that it is related to the fact that...
13
by: John Harrison | last post by:
If you specify an allocator in an STL container is it a requirement that the allocator allocates object of the right type, or can you assume that the container will rebind the allocator to the...
7
by: Matthias Käppler | last post by:
Hi, I have the following problem: I want to store file objects in a container 8for now, it's not important how they look like). Now, on the one hand I need to be able to randomly pick files...
2
by: utab | last post by:
Hi there, Can you please explain me why there are sequential and associative containers in c++ on some examples and briefly specify the advantages of using one over the other(and also from the...
5
by: desktop | last post by:
set, map, multiset and multimap are all associative containers. But what does the word "associative" have to do with these 4 containers?
3
by: subramanian100in | last post by:
I am copying the following lines as it is, from Stanley Lippman's C++ Primer 4th edition, page 418(First paragraph). It says: "Although the map and set types provide bidirectional iterators, we...
4
by: Morten | last post by:
Hi. Is there anybody who knows a C (not c++) library containing implementations of associative containers (stack, queue, hash table, linked list). It would be great if the performance of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.