mirror of
https://github.com/boostorg/type_traits.git
synced 2025-07-29 20:17:21 +02:00
integral_constant
: MPL interop: Avoid reinterpret_cast
.
Conversion between pointers to unrelated types `Source` and `Target` can be done with two `static_cast`'s ("upcast" to pointer to cv-void followed by "downcast") => (IMO) it should be done with `static_cast` (in order not to give the impression that `reinterpret_cast` really is needed): `T *ptr_target = static_cast <T *> (static_cast <void *> (ptr_source));` (Maybe that was the original intent of introducing `pdata`.)
This commit is contained in:
@ -61,7 +61,7 @@ namespace boost{
|
||||
{
|
||||
static const char data[sizeof(long)] = { 0 };
|
||||
static const void* pdata = data;
|
||||
return *(reinterpret_cast<const mpl::integral_c<T, val>*>(pdata));
|
||||
return *static_cast<const mpl::integral_c<T, val>*>(pdata);
|
||||
}
|
||||
BOOST_CONSTEXPR operator T()const { return val; }
|
||||
};
|
||||
@ -81,7 +81,7 @@ namespace boost{
|
||||
{
|
||||
static const char data[sizeof(long)] = { 0 };
|
||||
static const void* pdata = data;
|
||||
return *(reinterpret_cast<const mpl::bool_<val>*>(pdata));
|
||||
return *static_cast<const mpl::bool_<val>*>(pdata);
|
||||
}
|
||||
BOOST_CONSTEXPR operator bool()const { return val; }
|
||||
};
|
||||
|
Reference in New Issue
Block a user