分享

C++容器类未定义行为总结

 quandsu 2016-09-29
1.array (C11)    
back(): Calling this function on an empty container causes undefined behavior
front(): Calling this function on an empty container causes undefined behavior
operator[]: If the container size is greater than n, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavio
   
2.deque    
back(): Calling this function on an empty container causes undefined behavior
front(): Calling this function on an empty container causes undefined behavior.
assing(): If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if the range specified by [first,last) is not valid, it causes undefined behavior
emplace()(C11): If allocator_traits::construct is not supported with the appropriate arguments, or if position is not valid, it causes undefined behavior
emplace_back()(C11): If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior
emplace_front()(C11): If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior
erase(): Invalid ranges produce undefined behavior
insert(): If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if an invalid position or range is specified, it causes undefined behavior
operator=: If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if value_type is not copy assignable (or move assignable for (2)), it causes undefined behavio
operator[]: If the container size is greater than n, the function never throws exceptions (no-throw guarantee).
Otherwise, the behavior is undefined (which may include throwing)
pop_back(): If the container is not empty, the function never throws exceptions (no-throw guarantee).
Otherwise, the behavior is undefined
pop_front(): If the container is not empty, the function never throws exceptions (no-throw guarantee).
Otherwise, the behavior is undefined
push_back(): If allocator_traits::construct is not supported with val as argument, it causes undefined behavior
push_front(): If allocator_traits::construct is not supported with val as argument, it causes undefined behavior
swap(): If the allocators in both containers compare equal, or if their allocator traits indicate that the allocators shall propagate, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior
3.forward_list(C11)    
assign(): If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if the range specified by [first,last) is not valid, it causes undefined behavior.
emplace_after(): If allocator_traits::construct is not supported with the appropriate arguments, or if position is not valid, it causes undefined behavior
emplace_front(): If allocator_traits::construct is not supported with the appropriate arguments, or if position is not valid, it causes undefined behavior
erase_after(): If position (or the range) is valid, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior
front(): Calling this function on an empty container causes undefined behavior
insert(): If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if an invalid position or range is specified, it causes undefined behavior
merge(): If the allocators in both containers do not compare equal, if comp does not define a strict weak ordering, or if the container elements are not ordered according to it, it causes undefined behavior
operator=: If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if value_type is not copy assignable (or move assignable for (2)), it causes undefined behavior
pop_front(): If the container is not empty, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior.
push_front(): If allocator_traits::construct is not supported with val as argument, it causes undefined behavior.
splice_after(): If the allocators in both containers do not compare equal, if any of the iterators or ranges specified is not valid, or if x is *this in (1), or if position is in the range [first,last) in (3), it causes undefined behavior
swap(): If the allocators in both containers compare equal, or if their allocator traits indicate that the allocators shall propagate, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior
   
   
3.List    
assign(): If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if the range specified by [first,last) is not valid, it causes undefined behavior
back(): Calling this function on an empty container causes undefined behavior
front(): Calling this function on an empty container causes undefined behavior
emplace()(C11): If allocator_traits::construct is not supported with the appropriate arguments, or if position is not valid, it causes undefined behavior
emplace_back():(C11) If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior
emplace_front():(C11) If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior
erase(): If position (or the range) is valid, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavio
insert(): If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if an invalid position or range is specified, it causes undefined behavior
merge(): If the allocators in both containers do not compare equal, if comp does not define a strict weak ordering, or if the container elements are not ordered according to it, it causes undefined behavior
operator=: If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if value_type is not copy assignable (or move assignable for (2)), it causes undefined behavior
pop_back(): If the container is not empty, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior
pop_front(): If the container is not empty, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior
push_back(): If allocator_traits::construct is not supported with val as argument, it causes undefined behavior
push_front(): If allocator_traits::construct is not supported with val as argument, it causes undefined behavior
splice(): If the allocators in both containers do not compare equal, if any of the iterators or ranges specified is not valid, or if x is *this in (1), or if position is in the range [first,last) in (3), it causes undefined behavior
swap(): If the allocators in both containers compare equal, or if their allocator traits indicate that the allocators shall propagate, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavio
   
4.Map    
emplace():(C11) If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior
emplace_hint():(C11) If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior
erase(): If an invalid position or range is specified, it causes undefined behavior
insert(): If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if an invalid position is specified, it causes undefined behavior
operator=: If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if value_type is not copy assignable (or move assignable for (2)), it causes undefined behavior.
operator[]: If a new element is inserted and allocator_traits::construct cannot construct an element with k and a default-constructed mapped_type (or if mapped_type is not default constructible), it causes undefined behavior
swap(): If the allocators in both containers compare equal, or if their allocator traits indicate that the allocators shall propagate, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior
   
5.Multimap    
emplace():(C11) If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior
emplace_hint():(C11) If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior
erase(): If an invalid position or range is specified, it causes undefined behavior.
insert(): If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if an invalid position is specified, it causes undefined behavior
operator=: If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if value_type is not copy assignable (or move assignable for (2)), it causes undefined behavior
swap(): If the allocators in both containers compare equal, or if their allocator traits indicate that the allocators shall propagate, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior
   
5.queue    
back(): Calling this function on an empty container causes undefined behavior
front(): Calling this function on an empty container causes undefined behavior
emplace():(C11) If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior
pop(): If the container is not empty, the function never throws exceptions (no-throw guarantee).
Otherwise, the behavior is undefined
push(): If allocator_traits::construct is not supported with val as argument, it causes undefined behavior.
swap():(C11) If the allocators in both compare compare equal, or if their allocator traits indicate that the allocators shall propagate, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior
   
6.priority_queue    
emplace():(C11) If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior.
pop(): If the container is not empty, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior
push(): If allocator_traits::construct is not supported with val as argument, it causes undefined behavior
swap():(C11) If the allocators in both vectors compare equal, or if their allocator traits indicate that the allocators shall propagate, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior
top(): Calling this function on an empty container causes undefined behavior
8.set    
emplace():(C11) If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior
emplace_hint():(C11) If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if an invalid position is specified, it causes undefined behavior
erase(): If an invalid position or range is specified, it causes undefined behavior
insert(): If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if an invalid position is specified, it causes undefined behavior
operator(): If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if value_type is not copy assignable (or move assignable for (2)), it causes undefined behavior
swap(): If the allocators in both containers compare equal, or if their allocator traits indicate that the allocators shall propagate, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior
   
9.multiset    
emplace():(C11) If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior
emplace_hint():(C11) If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior.
erase(): If an invalid position or range is specified, it causes undefined behavior
insert(): If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if an invalid position is specified, it causes undefined behavior
operator=: If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if value_type is not copy assignable (or move assignable for (2)), it causes undefined behavior
swap(): If the allocators in both containers compare equal, or if their allocator traits indicate that the allocators shall propagate, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior
   
10.Stack    
pop(): If the container is not empty, the function never throws exceptions (no-throw guarantee).
Otherwise, the behavior is undefined
push(): If allocator_traits::construct is not supported with val as argument, it causes undefined behavior
emplace():(c11) If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior
swap():(C11) If the allocators in both compare compare equal, or if their allocator traits indicate that the allocators shall propagate, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior
top(): If the container is not empty, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior.
11.Vector    
assign(): If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if the range specified by [first,last) is not valid, it causes undefined behavior
back(): Calling this function on an empty container causes undefined behavior
front(): Calling this function on an empty container causes undefined behavior
emplace():(c11) If allocator_traits::construct is not supported with the appropriate arguments, or if position is not valid, it causes undefined behavio
emplace_back():(C11) If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior
erase(): An invalid position or range causes undefined behavior
insert(): If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if an invalid position or range is specified, it causes undefined behavior
operator=: If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if value_type is not copy assignable (or move assignable for (2)), it causes undefined behavior
operator[]: If the container size is greater than n, the function never throws exceptions (no-throw guarantee).
Otherwise, the behavior is undefined.
pop_back(): If the container is not empty, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior
push_back(): If allocator_traits::construct is not supported with val as argument, it causes undefined behavior
swap(): If the allocators in both vectors compare equal, or if their allocator traits indicate that the allocators shall propagate, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多