cast: add alignment cast
This commit is contained in:
parent
2926776c97
commit
06e29ed136
15
cast.hpp
15
cast.hpp
@ -152,6 +152,21 @@ namespace util::cast {
|
||||
CHECK_NOTHROW (dynamic_cast<T> (v));
|
||||
return static_cast<T> (v);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// cast a pointer from one type to another, asserting that the required
|
||||
/// alignment of the destination type has been satisfied.
|
||||
template <typename DstT, typename SrcT>
|
||||
DstT*
|
||||
alignment (SrcT *src)
|
||||
{
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
CHECK_MOD (reinterpret_cast<uintptr_t> (src), alignof (DstT));
|
||||
return reinterpret_cast<DstT*> (src);
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user