Reference:
https://howardhinnant.github.io/allocator_boilerplate.html
http://en.cppreference.com/w/cpp/container/vector/operator%3D
http://en.cppreference.com/w/cpp/memory/allocator_traits
C++11 and forward:
The commented out code represents functionality that std::allocator_traits<allocator<T>> defaults for us.
Notes:
https://howardhinnant.github.io/allocator_boilerplate.html
http://en.cppreference.com/w/cpp/container/vector/operator%3D
http://en.cppreference.com/w/cpp/memory/allocator_traits
C++11 and forward:
The commented out code represents functionality that std::allocator_traits<allocator<T>> defaults for us.
Notes:
- is_always_equal is new for C++11 (
hopefully that will be C++17). It is now in C++17. - The default implementation for max_size() is not incredibly useful.
Better if:
- Under discussion is the possibility to remove the requirement that you provide operator== and operator!= if is_always_equal{} is true.
- The nested types reference and const_reference are no longer required in C++11 (as they were in C++03).
- The member functions address(reference) and address(const_reference) are no longer required in C++11 (as they were in C++03).
- Allocator must be CopyConstructible and MoveConstructible. If propagate_on_container_copy_assignment{} is true,
- allocator must be CopyAssignable if propagate_on_container_move_assignment{} is true, allocator must be MoveAssignable.
- If propagate_on_container_swap{} is true, allocator must be Swappable.
- If they exist, these operations should not propagate an exception out.
- However they do not need to be marked with noexcept.
Recommend marking them with noexcept if the compiler does not implicitly do so,
so that traits such as is_nothrow_copy_constructible<allocator<T>> give the right answer. - If two allocators compare equal, that means that they can deallocate each other's allocated pointers.
- If two instances of your allocators can't do this, they must not compare equal to each other, else run time errors will result.
- However copies, even converting copies, are required to compare equal.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.