Topic: Difference Between vector<T> and T[n]
Author: "Dave Abrahams" <abrahams@mediaone.net>
Date: 1999/12/10 Raw View
In article <384E739F.1FBDEAB@nortelnetworks.com> , "John Hickin"
<hickin@nortelnetworks.com> wrote:
> Is there a specialization of destroy that alows reverse iteration? If
> not, does this represent an omission?
No (unless a vendor chooses to supply one), and no (unless your expectations
are wrong).
In short, not destroying objects in an array in reverse order of
construction need not, in and of itself, present an exception-safety problem
for users assuming they're well-informed about what the actual guarantees
are.
-Dave
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/12/11 Raw View
John Hickin wrote:
>
> If T has a default constructor that throws then the array T[n] may not
> be wholly constructed; I assume that the unwind is done in reverse order
> of construction.
>
> If I now use vector<T> t(n) I'm not so sure that the destruction will be
> done in reverse order. Take, for example, the uninitialized_fill
> template. I'd expect it to catch exceptions and use destroy; here,
> however, not all containers support reverse iteration, so the elements
> may be destroyed in construction order, not the reverse thereof.
It isn't the container or unitialized_fill that's relevant, but rather
Allocator::allocate(), Allocator::construct(), and Allocator::destroy().
Allocator::pointer, the type returned by allocate(), is required to be a
random access iterator. All standard containers are supposed to use
their Allocator object for all memory allocations, and will therefore
need to use construct() and destroy() (the parameters required by
unitialized_fill won't necessarily have the right type).
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "John Hickin" <hickin@nortelnetworks.com>
Date: 1999/12/09 Raw View
If T has a default constructor that throws then the array T[n] may not
be wholly constructed; I assume that the unwind is done in reverse order
of construction.
If I now use vector<T> t(n) I'm not so sure that the destruction will be
done in reverse order. Take, for example, the uninitialized_fill
template. I'd expect it to catch exceptions and use destroy; here,
however, not all containers support reverse iteration, so the elements
may be destroyed in construction order, not the reverse thereof.
Is there a specialization of destroy that alows reverse iteration? If
not, does this represent an omission?
Regards, John.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]