mirror of
https://github.com/boostorg/core.git
synced 2025-11-29 13:50:10 +01:00
Update pointer_traits and to_address to reflect the design adopted for C++20
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
[/
|
||||
Copyright 2017 Glen Joseph Fernandes
|
||||
Copyright 2017-2018 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
@@ -20,8 +20,10 @@ The header <boost/core/pointer_traits.hpp> provides the class template
|
||||
`boost::pointer_traits` to facilitate use of pointer-like types. The C++11
|
||||
standard library introduced `std::pointer_traits` along with an allocator
|
||||
model which supported pointer-like types in addition to plain raw pointers.
|
||||
This implementation also supports C++98, and adds additional functionality
|
||||
for obtaining raw pointers from pointers.
|
||||
This implementation also supports C++98.
|
||||
|
||||
It also provides the function template `boost::to_address` to obtain a raw
|
||||
pointer from an object of any pointer-like type.
|
||||
|
||||
[endsect]
|
||||
|
||||
@@ -54,7 +56,6 @@ namespace boost {
|
||||
template<class U> using rebind = typename rebind_to<U>::type;
|
||||
|
||||
static pointer pointer_to(``['see below]`` v);
|
||||
static element_type* to_address(const pointer& v) noexcept;
|
||||
};
|
||||
|
||||
template<class T> struct pointer_traits<T*> {
|
||||
@@ -66,11 +67,13 @@ namespace boost {
|
||||
template<class U> using rebind = typename rebind_to<U>::type;
|
||||
|
||||
static pointer pointer_to(``['see below]`` v) noexcept;
|
||||
static element_type* to_address(pointer v) noexcept;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
typename pointer_traits<T>::element_type* to_address(const T& v) noexcept;
|
||||
constexpr T* to_address(T* v) noexcept;
|
||||
|
||||
template<class T>
|
||||
auto to_address(const T& v) noexcept;
|
||||
}
|
||||
```
|
||||
|
||||
@@ -93,39 +96,44 @@ namespace boost {
|
||||
|
||||
[section Member functions]
|
||||
|
||||
[variablelist pointer_traits
|
||||
[[`static pointer pointer_to(`['see below] `v);`]
|
||||
[variablelist
|
||||
[[`static pointer pointer_traits::pointer_to(`['see below] `v);`]
|
||||
[[variablelist
|
||||
[[Remark]
|
||||
[If `element_type` is a void type, the type of `v` is unspecified; otherwise,
|
||||
it is `element_type&`.]]
|
||||
[[Returns]
|
||||
[A pointer to `v` obtained by calling `T::pointer_to(v)`.]]]]]
|
||||
[[`static element_type* to_address(const pointer& v) noexcept;`]
|
||||
[[variablelist
|
||||
[[Requires] [`v` is not a null pointer.]]
|
||||
[[Returns]
|
||||
[A pointer of type `element_type*` that references the same location
|
||||
as the argument.]]]]]]
|
||||
|
||||
[variablelist pointer_traits<T*>
|
||||
[[`static pointer pointer_to(`['see below] `v) noexcept;`]
|
||||
[[`static pointer pointer_traits<T*>::pointer_to(`['see below] `v) noexcept;`]
|
||||
[[variablelist
|
||||
[[Remark]
|
||||
[If `element_type` is a void type, the type of `v` is unspecified; otherwise,
|
||||
it is `element_type&`.]]
|
||||
[[Returns] [The result of `boost::addressof(v)`.]]]]]
|
||||
[[Returns] [`addressof(v)`.]]]]]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Optional members]
|
||||
|
||||
[variablelist
|
||||
[[`static element_type* to_address(pointer v) noexcept;`]
|
||||
[[variablelist [[Returns] [The value of `v`.]]]]]]
|
||||
[[variablelist
|
||||
[[Returns]
|
||||
[A pointer of type `element_type*` that references the same location as the
|
||||
argument `p`.]]
|
||||
[[Note] [This function should be the inverse of `pointer_to`. If defined, it
|
||||
customizes the behavior of the non-member function `to_address`.]]]]]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Free functions]
|
||||
|
||||
[variablelist
|
||||
[[`template<class T> typename pointer_traits<T>::element_type*
|
||||
to_address(const T& v) noexcept;`]
|
||||
[[variablelist [[Returns] [`boost::pointer_traits<T>::to_address(v)`.]]]]]]
|
||||
[[`template<class T> constexpr T* to_address(T* v) noexcept;`]
|
||||
[[variablelist [[Returns] [`v`.]]]]]
|
||||
[[`template<class T> auto to_address(const T& v) noexcept;`]
|
||||
[[variablelist [[Returns] [`pointer_traits<T>::to_address(v)` if that
|
||||
expression is well-formed, otherwise `to_address(v.operator->())`.]]]]]]
|
||||
|
||||
[endsect]
|
||||
|
||||
@@ -133,8 +141,8 @@ namespace boost {
|
||||
|
||||
[section Acknowledgments]
|
||||
|
||||
Glen Fernandes implemented `pointer_traits` with reviews and guidance from
|
||||
Peter Dimov.
|
||||
Glen Fernandes implemented `pointer_traits` and `to_address` with reviews and
|
||||
guidance from Peter Dimov.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user