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:
Adder
2023-06-13 23:29:56 +03:00
committed by John Maddock
parent 4824c0fae4
commit 0422aebeb8

View File

@ -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; }
};