view: move alignment test for cast into the implementation

Moving the alignment test from SFINAE into the implementation as a
static_assert means that users don't need to include the implementation
for types where `cast` isn't called. Otherwise, iterator_traits requires
a definition to work with.
This commit is contained in:
Danny Robson 2019-05-15 13:03:38 +10:00
parent c7689960be
commit 644cae506f

View File

@ -434,20 +434,27 @@ namespace cruft {
std::is_pointer_v<BeginT> &&
std::is_pointer_v<EndT> &&
std::is_same_v<BeginT,EndT> &&
std::is_pointer_v<ValueT> &&
// The values they point to must allow for alignment in one
// direction or another.
(
sizeof (typename std::iterator_traits<BeginT>::value_type) %
sizeof (typename std::iterator_traits<ValueT>::value_type) == 0 ||
sizeof (typename std::iterator_traits<ValueT>::value_type) %
sizeof (typename std::iterator_traits<BeginT>::value_type) == 0
)
std::is_pointer_v<ValueT>
>
>
view<ValueT>
cast (void) const
{
// The values they point to must allow for alignment in one
// direction or another.
//
// We prefer a static_assert over SFINAE because it reduces the
// header burden for users (they do not need to include the
// implementation of the pointer values to satisfy
// iterator_traits), and it is quite unlikely we want to disable
// this only if alignment is incompatible).
static_assert (
sizeof (typename std::iterator_traits<BeginT>::value_type) %
sizeof (typename std::iterator_traits<ValueT>::value_type) == 0 ||
sizeof (typename std::iterator_traits<ValueT>::value_type) %
sizeof (typename std::iterator_traits<BeginT>::value_type) == 0
);
return {
cast::alignment<ValueT> (m_begin),
cast::alignment<ValueT> (m_end)