From 8b5aa7b6c40d70a7ec15b3ea485f28a142fb247c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 31 Mar 2017 19:52:21 +0200 Subject: QStringView: add an array ctor With sufficient enable_if magic, the array ctor can overload the pointer ctor and statically determine the size of the array passed. Consequently, remove the sizeof in QStringViewLiteral again. Change-Id: I486baa3cafefde60ccc5f2b47eb94ee53cefe63c Reviewed-by: Edward Welbourne --- src/corelib/tools/qstringview.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/corelib/tools/qstringview.cpp') diff --git a/src/corelib/tools/qstringview.cpp b/src/corelib/tools/qstringview.cpp index ec77e11740..341746e80a 100644 --- a/src/corelib/tools/qstringview.cpp +++ b/src/corelib/tools/qstringview.cpp @@ -260,9 +260,33 @@ QT_BEGIN_NAMESPACE Passing \c nullptr as \a str is safe and results in a null string view. - This constructor only participates in overload resolution if \c Char is a compatible - character type. The compatible character types are: \c QChar, \c ushort, \c char16_t and - (on platforms, such as Windows, where it is a 16-bit type) \c wchar_t. + This constructor only participates in overload resolution if \a + str is not an array and if \c Char is a compatible character + type. The compatible character types are: \c QChar, \c ushort, \c + char16_t and (on platforms, such as Windows, where it is a 16-bit + type) \c wchar_t. +*/ + +/*! + \fn QStringView::QStringView(const Char (&string)[N]) + + Constructs a string view on the character string literal \a string. + The length is set to \c{N-1}, excluding the trailing \{Char(0)}. + If you need the full array, use the constructor from pointer and + size instead: + + \code + auto sv = QStringView(array, std::size(array)); // using C++17 std::size() + \endcode + + \a string must remain valid for the lifetime of this string view + object. + + This constructor only participates in overload resolution if \a + string is an actual array and \c Char is a compatible character + type. The compatible character types are: \c QChar, \c ushort, \c + char16_t and (on platforms, such as Windows, where it is a 16-bit + type) \c wchar_t. */ /*! -- cgit v1.2.3