forked from boostorg/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype_id.qbk
More file actions
83 lines (80 loc) · 3.31 KB
/
type_id.qbk
File metadata and controls
83 lines (80 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
[section boost/python/type_id.hpp]
[section Introduction]
<boost/python/type_id.hpp> provides types and functions for runtime type identification like those of of `<typeinfo>`. It exists mostly to work around certain compiler bugs and platform-dependent interactions with shared libraries.
[endsect]
[section Class template `type_info`]
`type_info` instances identify a type. As `std::type_info` is specified to (but unlike its implementation in some compilers), `boost::python::type_info` never represents top-level references or cv-qualification (see section 5.2.8 in the C++ standard). Unlike `std::type_info`, `boost::python::type_info` instances are copyable, and comparisons always work reliably across shared library boundaries.
``
namespace boost { namespace python
{
class type_info : totally_ordered<type_info>
{
public:
// constructor
type_info(std::type_info const& = typeid(void));
// comparisons
bool operator<(type_info const& rhs) const;
bool operator==(type_info const& rhs) const;
// observers
char const* name() const;
};
}}
``
[section Class template `type_info` constructor]
``type_info(std::type_info const& = typeid(void));``
[variablelist
[[Effects][constructs a `type_info` object which identifies the same type as its argument.]]
[[Rationale][Since it is occasionally necessary to make an array of `type_info` objects a benign default argument is supplied. Note: this constructor does not correct for non-conformance of compiler `typeid()` implementations. See `type_id`, below.]]
]
[endsect]
[section Class template `type_info` comparison]
``bool operator<(type_info const &rhs) const;``
[variablelist
[[Effects][yields a total order over `type_info` objects.]]
]
``bool operator==(type_info const &rhs) const;``
[variablelist
[[Returns][`true` iff the two values describe the same type.]]
[[Note][The use of `totally_ordered<type_info>` as a private base class supplies operators `<=`, `>=`, `>`, and `!=`]]
]
[endsect]
[section Class template `type_info` observers]
``
char const* name() const;
``
[variablelist
[[Returns][The result of calling `name()` on the argument used to construct the object.]]
]
[endsect]
[endsect]
[section Functions]
``
std::ostream& operator<<(std::ostream&s, type_info const&x);
``
[variablelist
[[Effects][Writes a description of the type described by to `x` into s.]]
[[Rationale][Not every C++ implementation provides a truly human-readable `type_info::name()` string, but for some we may be able to decode the string and produce a reasonable representation.]]
[[Note][On some non-conforming C++ implementations, the code is not actually as simple as described above; the semantics are adjusted to work as-if the C++ implementation were conforming.]]
]
``
template <class T> type_info type_id()
``
[variablelist
[[Returns][`type_info(typeid(T))`]]
[[Note][On some non-conforming C++ implementations, the code is not actually as simple as described above; the semantics are adjusted to work as-if the C++ implementation were conforming.]]
]
[endsect]
[section Example]
The following example, though silly, illustrates how the type_id facility might be used
``
#include <boost/python/type_id.hpp>
// Returns true iff the user passes an int argument
template <class T>
bool is_int(T x)
{
using boost::python::type_id;
return type_id<T>() == type_id<int>();
}
``
[endsect]
[endsect]