2014-06-10 13:25:46 +03:00
|
|
|
[/
|
|
|
|
Copyright 2014 Peter Dimov
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0.
|
|
|
|
|
|
|
|
See accompanying file LICENSE_1_0.txt
|
|
|
|
or copy at http://boost.org/LICENSE_1_0.txt
|
|
|
|
]
|
|
|
|
|
2014-06-05 10:48:21 -07:00
|
|
|
[section:addressof addressof]
|
|
|
|
|
2014-06-10 19:12:54 +03:00
|
|
|
[simplesect Authors]
|
2014-06-05 10:48:21 -07:00
|
|
|
|
|
|
|
* Brad King
|
|
|
|
* Douglas Gregor
|
|
|
|
* Peter Dimov
|
2017-03-03 21:31:29 -05:00
|
|
|
* Glen Fernandes
|
2014-06-05 10:48:21 -07:00
|
|
|
|
2014-06-10 19:12:54 +03:00
|
|
|
[endsimplesect]
|
2014-06-05 10:48:21 -07:00
|
|
|
|
|
|
|
[section Header <boost/core/addressof.hpp>]
|
2014-06-01 18:08:55 -07:00
|
|
|
|
|
|
|
The header `<boost/core/addressof.hpp>` defines the function
|
|
|
|
template `boost::addressof`. `boost::addressof(x)` returns the
|
|
|
|
address of `x`. Ordinarily, this address can be obtained by
|
2014-06-12 21:06:45 +04:00
|
|
|
`&x`, but the unary `&` operator can be overloaded. `boost::addressof`
|
|
|
|
avoids calling used-defined `operator&()`.
|
2014-06-01 18:08:55 -07:00
|
|
|
|
|
|
|
`boost::addressof` was originally contributed by Brad King
|
|
|
|
based on ideas from discussion with Doug Gregor.
|
|
|
|
|
2014-06-10 13:25:46 +03:00
|
|
|
[section Synopsis]
|
|
|
|
|
|
|
|
``
|
|
|
|
namespace boost
|
|
|
|
{
|
|
|
|
template<class T> T* addressof( T& x );
|
|
|
|
}
|
|
|
|
``
|
|
|
|
|
2014-06-01 18:08:55 -07:00
|
|
|
[endsect]
|
2014-06-05 10:48:21 -07:00
|
|
|
|
|
|
|
[section Example]
|
|
|
|
|
|
|
|
``
|
|
|
|
#include <boost/core/addressof.hpp>
|
|
|
|
|
|
|
|
struct useless_type { };
|
|
|
|
|
|
|
|
class nonaddressable {
|
|
|
|
useless_type operator&() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
void f() {
|
|
|
|
nonaddressable x;
|
|
|
|
nonaddressable* xp = boost::addressof(x);
|
|
|
|
// nonaddressable* xpe = &x; /* error */
|
|
|
|
}
|
|
|
|
``
|
|
|
|
|
|
|
|
[endsect]
|
|
|
|
|
2017-03-03 21:55:48 -05:00
|
|
|
[section Notes]
|
|
|
|
|
|
|
|
In C++11 and above, `boost::addressof` is conditionally
|
|
|
|
`constexpr` when possible. This is indicated by
|
|
|
|
`BOOST_CORE_NO_CONSTEXPR_ADDRESSOF` not being defined.
|
|
|
|
|
|
|
|
With supported compilers, `boost::addressof` is always
|
|
|
|
`constexpr` by leveraging compiler intrinsics. This is
|
|
|
|
indicated by `BOOST_CORE_HAS_BUILTIN_ADDRESSOF` being
|
|
|
|
defined.
|
|
|
|
|
|
|
|
[endsect]
|
|
|
|
|
2014-06-05 10:48:21 -07:00
|
|
|
[endsect]
|
2014-06-10 13:25:46 +03:00
|
|
|
|
|
|
|
[endsect]
|