diff --git a/view.hpp b/view.hpp index 445d9859..efc1bc9f 100644 --- a/view.hpp +++ b/view.hpp @@ -724,20 +724,24 @@ namespace cruft { /// It is assumed the user has taken care of alignment concerns template < typename ValueT, - typename WordT, - typename = std::enable_if_t< - // Only allow calls if the value is a multiple of the word size. - // It's useful to allow non-unit words for areas like TCP/IP which - // tend to include protocols that utilise u16 words. - sizeof (ValueT) % sizeof (WordT) == 0 && - // If WordT is const then ValueT must be const. Otherwise the user - // is free to choose. - std::is_const_v ? std::is_const_v : true - > + typename WordT > ValueT& extract (view &buffer) { + // Only allow calls if the value is a multiple of the word size. + // It's useful to allow non-unit words for areas like TCP/IP which + // tend to include protocols that utilise u16 words. + static_assert ( + sizeof (ValueT) % sizeof (WordT) == 0, + "The value type must be a multiple of the word size" + ); + + static_assert ( + !std::is_const_v or std::is_const_v, + "buffer and output types must have matching constness" + ); + if (unlikely (sizeof (ValueT) > buffer.size () * sizeof (WordT))) throw std::runtime_error ("insufficient data for extraction");