diff --git a/gsl/span b/gsl/span index 0651329..a46d3bf 100644 --- a/gsl/span +++ b/gsl/span @@ -308,7 +308,7 @@ namespace details constexpr extent_type() noexcept {} template - constexpr extent_type(extent_type ext) + constexpr extent_type(extent_type ext) { static_assert(Other == Ext || Other == dynamic_extent, "Mismatch between fixed-size extent and size of initializing data."); @@ -632,6 +632,22 @@ as_writeable_bytes(span s) noexcept return {reinterpret_cast(s.data()), s.size_bytes()}; } + +template ::value>> +span +as_bytes(const T& e) noexcept +{ + return {reinterpret_cast(&e), sizeof(e)}; +} + +template ::value>> +span +as_writeable_bytes(T& e) noexcept +{ + static_assert(!std::is_const::value,"Can't create a span of writeable bytes over a const object"); + return {reinterpret_cast(&e), sizeof(e)}; +} + // // make_span() - Utility functions for creating spans // @@ -670,19 +686,6 @@ span make_span(Ptr& cont) { return span(cont); } -template ::value>> -span -as_bytes(const T& e) noexcept -{ - return{ reinterpret_cast(&e),sizeof(T) }; -} - -template ::value>> -span -as_writeable_bytes(T& e) noexcept -{ - return{ reinterpret_cast(&e),sizeof(T) }; -} // Specialization of gsl::at for span template