From 644cae506f3ff6299ae1c4dd482f60bf4abae30c Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 15 May 2019 13:03:38 +1000 Subject: [PATCH] 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. --- view.hpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/view.hpp b/view.hpp index 0a50c6b3..5fdeb1c5 100644 --- a/view.hpp +++ b/view.hpp @@ -434,20 +434,27 @@ namespace cruft { std::is_pointer_v && std::is_pointer_v && std::is_same_v && - std::is_pointer_v && - // The values they point to must allow for alignment in one - // direction or another. - ( - sizeof (typename std::iterator_traits::value_type) % - sizeof (typename std::iterator_traits::value_type) == 0 || - sizeof (typename std::iterator_traits::value_type) % - sizeof (typename std::iterator_traits::value_type) == 0 - ) + std::is_pointer_v > > view 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::value_type) % + sizeof (typename std::iterator_traits::value_type) == 0 || + sizeof (typename std::iterator_traits::value_type) % + sizeof (typename std::iterator_traits::value_type) == 0 + ); + return { cast::alignment (m_begin), cast::alignment (m_end)