|
22 | 22 | // _Py_CAST(PyObject*, op) can convert a "const PyObject*" to
|
23 | 23 | // "PyObject*".
|
24 | 24 | //
|
25 |
| -// The type argument must not be constant. For example, in C++, |
26 |
| -// _Py_CAST(const PyObject*, expr) fails with a compiler error. |
| 25 | +// The type argument must not be a constant type. |
27 | 26 | #ifdef __cplusplus
|
28 | 27 | # define _Py_STATIC_CAST(type, expr) static_cast<type>(expr)
|
29 |
| - |
30 | 28 | extern "C++" {
|
31 |
| -namespace { |
32 |
| -template <typename type, typename expr_type> |
33 |
| -inline type _Py_reinterpret_cast_impl(expr_type *expr) { |
34 |
| - return reinterpret_cast<type>(expr); |
35 |
| -} |
36 |
| - |
37 |
| -template <typename type, typename expr_type> |
38 |
| -inline type _Py_reinterpret_cast_impl(expr_type const *expr) { |
39 |
| - return reinterpret_cast<type>(const_cast<expr_type *>(expr)); |
40 |
| -} |
41 |
| - |
42 |
| -template <typename type, typename expr_type> |
43 |
| -inline type _Py_reinterpret_cast_impl(expr_type &expr) { |
44 |
| - return static_cast<type>(expr); |
45 |
| -} |
46 |
| - |
47 |
| -template <typename type, typename expr_type> |
48 |
| -inline type _Py_reinterpret_cast_impl(expr_type const &expr) { |
49 |
| - return static_cast<type>(const_cast<expr_type &>(expr)); |
50 |
| -} |
51 |
| -} // namespace |
| 29 | + namespace { |
| 30 | + template <typename type, typename expr_type> |
| 31 | + inline type _Py_CAST_impl(expr_type *expr) { |
| 32 | + return reinterpret_cast<type>(expr); |
| 33 | + } |
| 34 | + |
| 35 | + template <typename type, typename expr_type> |
| 36 | + inline type _Py_CAST_impl(expr_type const *expr) { |
| 37 | + return reinterpret_cast<type>(const_cast<expr_type *>(expr)); |
| 38 | + } |
| 39 | + |
| 40 | + template <typename type, typename expr_type> |
| 41 | + inline type _Py_CAST_impl(expr_type &expr) { |
| 42 | + return static_cast<type>(expr); |
| 43 | + } |
| 44 | + |
| 45 | + template <typename type, typename expr_type> |
| 46 | + inline type _Py_CAST_impl(expr_type const &expr) { |
| 47 | + return static_cast<type>(const_cast<expr_type &>(expr)); |
| 48 | + } |
| 49 | + } |
52 | 50 | }
|
53 |
| -# define _Py_CAST(type, expr) _Py_reinterpret_cast_impl<type>(expr) |
| 51 | +# define _Py_CAST(type, expr) _Py_CAST_impl<type>(expr) |
54 | 52 |
|
55 | 53 | #else
|
56 | 54 | # define _Py_STATIC_CAST(type, expr) ((type)(expr))
|
|
0 commit comments