qt5base-lts/src
Marc Mutz f82cf6333e Long live QSpan!
QSpan is Qt's version of std::span. While we usually try not to
reimplement std functionality anymore, the situation is different with
QSpan. Spans are non-owning containers, so the usual impedance
mismatch between owning STL and Qt containers doesn't apply here:
QSpan implicitly converts to std::span and vice versa, making STL and
Qt APIs using spans completely interoperable.

We add QSpan mainly for two reasons: First, we don't want to wait
until we require C++20 in Qt and can use std::span. Second, in the
view of this author, some design decisions in std::span hurt the
primary use-case of spans: type-erasure for containers. This results
in two major deviations of QSpan from std::span: First, any rvalue
container is convertible to QSpan, allowing seamless passing of owning
containers to functions taking spans:

    void sspan(std::span<T>);
    void qspan(QSpan<T>);

    std::vector<T> v();
    sspan(v()); // ERROR: rvalue owning container
    auto tmp = v();
    sspan(tmp); // OK, lvalue
    qspan(v()); // OK

This author believes that it's more helpful to have compilers and
static checkers warn about a particular wrong usage than to make
perfectly valid use-cases impossible or needlessly verbose to code.

The second deviation from std::span is that fixed-size span
constructors are also implicit. This isn't as clear-cut, because an
explicit QSpan{arg} isn't per-se bad. However, it means you can't
transparently change from a function taking decltype(arg) to one
taking QSpan and back. Since that's exactly what we intend to do in Qt
going forward, in the interest of source-compatibility, the ctors are
all implicit.

Otherwise, the API of QSpan follows the std::span API very
closely. Like std::span, QSpan isn't equality_comparable, because it's
not clear what equality means for spans (element-wise equal, or (ptr,
size)-wise equal?). The major API additions are Qt-ish versions of std
API functions: isEmpty() on top of empty() and sliced() instead of
subspan(). The (nullary) first()/last() functions (Qt speak for
front()/back()) clash with the std::span function templates of the
same name, so are not provided.

This patch adds QSpan as private API. We intend to make it public API
in the future.

Pick-to: 6.6
Fixes: QTBUG-108124
Change-Id: I3f660be90eb408b9e66ff9eacf5da4cba17212a6
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-07-21 17:00:05 +00:00
..
3rdparty Update public suffix list 2023-07-06 17:53:11 +02:00
android Android: Fix for checking clipboard text mime type 2023-07-12 00:53:58 +02:00
assets Add XDG theme file for example icons 2023-06-26 17:32:10 +00:00
concurrent Enable QT_NO_CONTEXTLESS_CONNECT for most of QtBase 2023-07-11 22:44:29 +02:00
corelib Long live QSpan! 2023-07-21 17:00:05 +00:00
dbus Doc: List of all Qt overviews which are now termed as explanation 2023-07-19 10:36:59 +02:00
entrypoint src: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-10 23:36:51 +01:00
gui QIconLoader: add some more debugging help 2023-07-21 09:22:54 +02:00
network QHostInfo: fix leaking slot object 2023-07-19 14:16:55 +02:00
opengl Enable QT_NO_CONTEXTLESS_CONNECT for most of QtBase 2023-07-11 22:44:29 +02:00
openglwidgets Enable QT_NO_CONTEXTLESS_CONNECT for most of QtBase 2023-07-11 22:44:29 +02:00
platformsupport Implement virtual void QPlatformWindow::setBackingStore() 2023-07-14 18:40:43 +02:00
plugins SQL: use QT_NO_CONTEXTLESS_CONNECT for sql plugins 2023-07-19 18:42:46 +00:00
printsupport Enable QT_NO_CONTEXTLESS_CONNECT for most of QtBase 2023-07-11 22:44:29 +02:00
sql Do not generate the deprecated 'QtSql/qsql.h' 2023-07-19 13:51:36 +02:00
testlib Doc: Change the Qt Testlib example pages 2023-07-21 13:08:03 +02:00
tools Make sure that the 3rdparty directory belongs to the module 2023-07-19 21:06:12 +02:00
widgets QtWidgets: unbreak unity-build-batch-size 100000 2023-07-21 12:31:45 +02:00
xml Doc: List of all Qt overviews which are now termed as explanation 2023-07-19 10:36:59 +02:00
CMakeLists.txt Add Qt icon library for examples 2023-04-22 18:14:38 +03:00