mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Fix etl::as_bytes for etl::span<const T> (#1266)
A missing 'const' in the etl::as_bytes implementation was causing a compile-time error when etl::as_bytes was called on a span of const values. Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
This commit is contained in:
parent
c92dbc2fce
commit
55503e0b97
@ -1303,7 +1303,7 @@ namespace etl
|
||||
span<const byte, (Size == etl::dynamic_extent) ? (etl::dynamic_extent) : (Size * sizeof(T))>
|
||||
as_bytes(span<T, Size> s) ETL_NOEXCEPT
|
||||
{
|
||||
return span<const byte, (Size == etl::dynamic_extent) ? (etl::dynamic_extent) : (Size * sizeof(T))>(reinterpret_cast<byte*>(s.data()), s.size_bytes());
|
||||
return span<const byte, (Size == etl::dynamic_extent) ? (etl::dynamic_extent) : (Size * sizeof(T))>(reinterpret_cast<const byte*>(s.data()), s.size_bytes());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -1325,8 +1325,9 @@ namespace
|
||||
TEST(test_convert_span_any_to_span_byte)
|
||||
{
|
||||
float data[2]{3.141592f, 2.71828f };
|
||||
const float const_data[2]{3.141592f, 2.71828f };
|
||||
|
||||
auto const const_bytes = etl::as_bytes(etl::span<float, etl::dynamic_extent>{data});
|
||||
auto const const_bytes = etl::as_bytes(etl::span<const float, etl::dynamic_extent>{const_data});
|
||||
auto const writable_bytes = etl::as_writable_bytes(etl::span<float, etl::dynamic_extent>{data});
|
||||
|
||||
CHECK_EQUAL(const_bytes.size(), sizeof(data));
|
||||
|
||||
@ -1163,12 +1163,13 @@ namespace
|
||||
TEST(test_convert_span_any_to_span_byte)
|
||||
{
|
||||
float data[2]{3.141592f, 2.71828f};
|
||||
const float const_data[2]{3.141592f, 2.71828f};
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
auto const const_bytes = etl::as_bytes(etl::span{ data });
|
||||
auto const const_bytes = etl::as_bytes(etl::span{ const_data });
|
||||
auto const writable_bytes = etl::as_writable_bytes(etl::span{ data });
|
||||
#else
|
||||
auto const const_bytes = etl::as_bytes(etl::span<float, 2>(data));
|
||||
auto const const_bytes = etl::as_bytes(etl::span<const float, 2>(const_data));
|
||||
auto const writable_bytes = etl::as_writable_bytes(etl::span<float, 2>(data));
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user