mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Bugfix: Fixed span reinterpret_as should return fixed span (#1210)
* Fixed span reinterpret should also return fixed span * Use auto instead of CTAD
This commit is contained in:
parent
b6e78b7c9c
commit
81a643b9b5
@ -561,11 +561,11 @@ namespace etl
|
||||
/// Reinterpret the span as a span with different element type.
|
||||
//*************************************************************************
|
||||
template<typename TNew>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 etl::span<TNew, etl::dynamic_extent> reinterpret_as() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 etl::span<TNew, Extent * sizeof(element_type) / sizeof(TNew)> reinterpret_as() const
|
||||
{
|
||||
ETL_ASSERT(etl::is_aligned<etl::alignment_of<TNew>::value>(pbegin), ETL_ERROR(span_alignment_exception));
|
||||
|
||||
return etl::span<TNew, etl::dynamic_extent>(reinterpret_cast<TNew*>(pbegin),
|
||||
return etl::span<TNew, Extent * sizeof(element_type) / sizeof(TNew)>(reinterpret_cast<TNew*>(pbegin),
|
||||
Extent * sizeof(element_type) / sizeof(TNew));
|
||||
}
|
||||
|
||||
|
||||
@ -1223,7 +1223,7 @@ namespace
|
||||
uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
||||
etl::span<uint8_t, 5> data0 = data;
|
||||
|
||||
etl::span<etl::be_uint16_t> data1 = data0.reinterpret_as<etl::be_uint16_t>();
|
||||
auto data1 = data0.reinterpret_as<etl::be_uint16_t>();
|
||||
|
||||
CHECK_EQUAL(data1.size(), 2);
|
||||
CHECK(data1[0] == 0x102);
|
||||
@ -1237,13 +1237,13 @@ namespace
|
||||
etl::span<uint32_t, 3> data0 = data;
|
||||
CHECK_EQUAL(data0.size(), 3);
|
||||
|
||||
etl::span<uint8_t> data1 = data0.reinterpret_as<uint8_t>();
|
||||
auto data1 = data0.reinterpret_as<uint8_t>();
|
||||
CHECK_EQUAL(data1.size(), 12);
|
||||
|
||||
etl::span<uint16_t> data2 = data1.subspan(2).reinterpret_as<uint16_t>();
|
||||
auto data2 = data1.subspan<2>().reinterpret_as<uint16_t>();
|
||||
CHECK_EQUAL(data2.size(), 5);
|
||||
|
||||
CHECK_THROW(data2 = data1.subspan(1).reinterpret_as<uint16_t>(), etl::span_alignment_exception);
|
||||
CHECK_THROW(data2 = data1.subspan<1>().reinterpret_as<uint16_t>(), etl::span_alignment_exception);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user