QSpan: check conversion from initializer_list
The docs at cppreference.com hint at a corresponding ctor being added for C++26 (though I don't see it in eel.is/c++draft, yet). Even so, replacing former initializer_list functions with QSpan ones is definitely one of the upcoming use-cases, so test it. Can't use from_container_impl() here as initializer_list<T> is already immutable, so QSpan<int> is not compatible, only QSpan<const int>. Change-Id: Iecdf29e629d48313edd5e56d358b9137da76deb6 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit c851fb2456a87d7b19e7fb9a5a61a3b631970026) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
89e8253de5
commit
1945c5f40c
@ -71,6 +71,7 @@ private Q_SLOTS:
|
||||
void zeroExtentSpansMaintainADataPointer() const;
|
||||
void fromArray() const;
|
||||
void fromStdArray() const;
|
||||
void fromStdInitializerList() const;
|
||||
void fromZeroSizeStdArray() const;
|
||||
void fromStdVector() const;
|
||||
void fromQList() const;
|
||||
@ -331,6 +332,21 @@ void tst_QSpan::fromStdArray() const
|
||||
from_container_impl<4>(ai);
|
||||
}
|
||||
|
||||
void tst_QSpan::fromStdInitializerList() const
|
||||
{
|
||||
std::initializer_list<int> il = {42, 84, 168, 336};
|
||||
|
||||
QSpan sci = il; // CTAD
|
||||
// special case: always deduced as <const int>:
|
||||
static_assert(std::is_same_v<decltype(sci), QSpan<const int>>);
|
||||
|
||||
QCOMPARE_EQ(sci.size(), qsizetype(il.size()));
|
||||
QCOMPARE_EQ(sci.data(), il.begin());
|
||||
|
||||
check_nonempty_span(sci, 4);
|
||||
RETURN_IF_FAILED();
|
||||
}
|
||||
|
||||
void tst_QSpan::fromZeroSizeStdArray() const
|
||||
{
|
||||
std::array<int, 0> ai = {};
|
||||
|
Loading…
x
Reference in New Issue
Block a user