diff --git a/view.hpp b/view.hpp index 3efc8bb1..63beba23 100644 --- a/view.hpp +++ b/view.hpp @@ -393,10 +393,34 @@ namespace cruft { /////////////////////////////////////////////////////////////////////// + /// Explicitly cast to a view with different iterator types. + /// + /// The source and destination iterator types must be: + /// * pointers + /// * alignable + /// + /// It is undefined behaviour to cast with begin and/or end iterators + /// that do not have natural alignment. Instrumented builds _may_ + /// provide diagnostics or assertions in this case. + /// + /// \tparam ValueT The new iterator type + /// \return A view that uses the new iterator type template < typename ValueT, typename = std::enable_if_t< - std::is_pointer_v && std::is_pointer_v + // We can only convert views that use pointer iterators + 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 + ) > > view