Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / core / doc / addressof.qbk
1 [/
2   Copyright 2014 Peter Dimov
3
4   Distributed under the Boost Software License, Version 1.0.
5
6   See accompanying file LICENSE_1_0.txt
7   or copy at http://boost.org/LICENSE_1_0.txt
8 ]
9
10 [section:addressof addressof]
11
12 [simplesect Authors]
13
14 * Brad King
15 * Douglas Gregor
16 * Peter Dimov
17
18 [endsimplesect]
19
20 [section Header <boost/core/addressof.hpp>]
21
22 The header `<boost/core/addressof.hpp>` defines the function
23 template `boost::addressof`. `boost::addressof(x)` returns the
24 address of `x`. Ordinarily, this address can be obtained by
25 `&x`, but the unary `&` operator can be overloaded. `boost::addressof`
26 avoids calling used-defined `operator&()`.
27
28 `boost::addressof` was originally contributed by Brad King
29 based on ideas from discussion with Doug Gregor.
30
31 [section Synopsis]
32
33 ``
34 namespace boost
35 {
36     template<class T> T* addressof( T& x );
37 }
38 ``
39
40 [endsect]
41
42 [section Example]
43
44 ``
45 #include <boost/core/addressof.hpp>
46
47 struct useless_type { };
48
49 class nonaddressable {
50     useless_type operator&() const;
51 };
52
53 void f() {
54     nonaddressable x;
55     nonaddressable* xp = boost::addressof(x);
56     // nonaddressable* xpe = &x; /* error */
57 }
58 ``
59
60 [endsect]
61
62 [endsect]
63
64 [endsect]