From 7f2645a4d979cfd3c36b52081d4424bc8cce5c82 Mon Sep 17 00:00:00 2001 From: MikeGitb Date: Thu, 8 Dec 2016 15:52:47 +0100 Subject: [PATCH] small fixes to as_bytes() for pod types - consistent enable_if clause between as_bytes and as_writable_bytes - Explicitly check for non-const as_writeable_bytes - move overloads to right section of the file --- gsl/span | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) 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