S
subramanian100in
In the ISO/IEC 14882:2003 document, in page 468 section '23.1
Container requirements', item 10 mentions the following:
"Unless otherwise specified (see 23.2.1.3 and 23.2.4.3) all container
types defined in this clause meet the following additional
requirements:
- if an exception is thrown by an insert() function while inserting
a single element, that function has no effects.
- if an exception is thrown by push_back() or push_front()
function, that function has no effects"
Then in page 480 section 23.2.1.3 - deque modifiers, item 2 says:
"Notes: if an exception is thrown other than by the copy constructor
or assignment operator of 'T', there are no effects."
(Here 'T' is the element type of the container).
My questions:
To me, there appears to be a difference between the statements in page
468 and page 480. However, since page 468 adds the words "unless
otherwise specified (see 23.2.1.3 and 23.2.4.3) ...", we have to
consider only the item 2 in page 480. Am I correct ?
Item 2 in page 480 section 23.2.1.3 - deque modifiers, says that "if
an exception is thrown other than by the copy constructor or
assignment operator of 'T', there are no effects." Given this, suppose
the copy ctor and assignment operator of 'T' do not throw any
exceptions, but due to non-availability of memory, suppose bad_alloc
exception is thrown by insert() or push_back() or push_front()
function. Then the original container on which these functions were
called, will be kept in tact(ie the container will not be modified at
all). Am I correct ?. Now suppose either the copy ctor or the
assignment operator of 'T' throws some exception. Then what will
happen to the container on which these functions were called ? Will it
be partially modified ?
For example, consider:
container.insert(iter, first, last);
When this function is called, while inserting the elements in the the
range [first, last) into 'container', suppose an exception is thrown
by either the copy ctor or the assignment operator of the element
type. Then will the 'container' maintain its original state before the
insert() was called or will there be some extra elements added to the
'container' prior to the exception thrown ?
Kindly explain.
Thanks
V.Subramanian
Container requirements', item 10 mentions the following:
"Unless otherwise specified (see 23.2.1.3 and 23.2.4.3) all container
types defined in this clause meet the following additional
requirements:
- if an exception is thrown by an insert() function while inserting
a single element, that function has no effects.
- if an exception is thrown by push_back() or push_front()
function, that function has no effects"
Then in page 480 section 23.2.1.3 - deque modifiers, item 2 says:
"Notes: if an exception is thrown other than by the copy constructor
or assignment operator of 'T', there are no effects."
(Here 'T' is the element type of the container).
My questions:
To me, there appears to be a difference between the statements in page
468 and page 480. However, since page 468 adds the words "unless
otherwise specified (see 23.2.1.3 and 23.2.4.3) ...", we have to
consider only the item 2 in page 480. Am I correct ?
Item 2 in page 480 section 23.2.1.3 - deque modifiers, says that "if
an exception is thrown other than by the copy constructor or
assignment operator of 'T', there are no effects." Given this, suppose
the copy ctor and assignment operator of 'T' do not throw any
exceptions, but due to non-availability of memory, suppose bad_alloc
exception is thrown by insert() or push_back() or push_front()
function. Then the original container on which these functions were
called, will be kept in tact(ie the container will not be modified at
all). Am I correct ?. Now suppose either the copy ctor or the
assignment operator of 'T' throws some exception. Then what will
happen to the container on which these functions were called ? Will it
be partially modified ?
For example, consider:
container.insert(iter, first, last);
When this function is called, while inserting the elements in the the
range [first, last) into 'container', suppose an exception is thrown
by either the copy ctor or the assignment operator of the element
type. Then will the 'container' maintain its original state before the
insert() was called or will there be some extra elements added to the
'container' prior to the exception thrown ?
Kindly explain.
Thanks
V.Subramanian