diff --git a/src/corelib/tools/qoffsetstringarray_p.h b/src/corelib/tools/qoffsetstringarray_p.h index a1117b1d47..ff195965ec 100644 --- a/src/corelib/tools/qoffsetstringarray_p.h +++ b/src/corelib/tools/qoffsetstringarray_p.h @@ -62,26 +62,23 @@ namespace QtPrivate { template struct OffsetSequenceHelper : OffsetSequenceHelper { }; -template -struct OffsetSequenceHelper<0, O, I, Idx...> : IndexesList +template +struct OffsetSequenceHelper<1, Last, I, S, Idx...> : IndexesList { - static const constexpr auto Length = O; -}; - -template -struct OffsetSequence : OffsetSequenceHelper -{ - static const constexpr auto Count = sizeof ... (Idx) + 1; + static const constexpr auto Length = Last + I; using Type = typename QConditional< - Count <= std::numeric_limits::max() + 1, + Last <= std::numeric_limits::max(), quint8, typename QConditional< - Count <= std::numeric_limits::max() + 1, + Last <= std::numeric_limits::max(), quint16, int>::Type >::Type; }; +template +struct OffsetSequence : OffsetSequenceHelper { }; + template struct StaticString { @@ -168,7 +165,7 @@ public: } constexpr inline const char *str() const { return m_string; } - constexpr inline const int *offsets() const { return m_offsets; } + constexpr inline const T *offsets() const { return m_offsets; } constexpr inline int count() const { return SizeOffsets; }; static constexpr const auto sizeString = SizeString; diff --git a/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp b/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp index 9174308a9a..dfa0450b18 100644 --- a/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp +++ b/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp @@ -81,6 +81,13 @@ constexpr const auto messages257 = qOffsetStringArray( "", "", "", "", "", "", "end" ); +constexpr const auto messagesBigOffsets = qOffsetStringArray( + " 10 20 30 40 50 60 70 80 90", + " 10 20 30 40 50 60 70 80 90", + " 10 20 30 40 50 60 70 80 90", + " 10 20 30 40 50 60 70 80 90" +); + void tst_QOffsetStringArray::init() { static_assert(messages.sizeString == 51, "message.sizeString"); @@ -91,6 +98,11 @@ void tst_QOffsetStringArray::init() static_assert(messages257.sizeString == 260, "messages257.sizeString"); static_assert(std::is_same::value, "messages257::Type != quint16"); + + static_assert(messagesBigOffsets.sizeOffsets == 4, "messagesBigOffsets.sizeOffsets"); + static_assert(messagesBigOffsets.sizeString == 364, "messagesBigOffsets.sizeString"); + static_assert(std::is_same::value, + "messagesBigOffsets::Type != quint16"); } void tst_QOffsetStringArray::access()