tst_Encoder: port away from Q_FOREACH#238
Merged
thiagomacieira merged 1 commit intointel:mainfrom Aug 7, 2023
marcmutz:Q_FOREACH
Merged
tst_Encoder: port away from Q_FOREACH#238thiagomacieira merged 1 commit intointel:mainfrom marcmutz:Q_FOREACH
thiagomacieira merged 1 commit intointel:mainfrom
marcmutz:Q_FOREACH
Conversation
Qt is defaulting to QT_NO_FOREACH these days, so make sure we integrate nicely with downstream and fix the single Q_FOREACH/foreach user, in tst_encoder.cpp. Unfortunately, the container's initialization code doesn't exactly lend itself to making the container const (not even IILE (Immediately-Invoked Lambda Expression) would help here, due to the interdependency with `len`), so the idiomatic solution would be to use std::as_const()/qAsConst(). The former is available from C++17, which we don't require, yet, and the latter is not available under QT_NO_AS_CONST (the default for Qt these days), so grab the nettle and implement a t17::as_const() that switches between a manual implementation of std::as_const and the real thing, depending on __cpp_lib_as_const. The `t17` here mimicks the qNN (q20::remove_cvref_t/q23::forward_like/etc) mechanism used in Qt itself for backports, with s/q/t/ because ... _T_inyCbor. The t17 implementation is local to tst_encoder.cpp, but can easily be extracted into a separate header once more users emerge.
thiagomacieira
approved these changes
Aug 7, 2023
qtprojectorg
pushed a commit
to qt/qtbase
that referenced
this pull request
Aug 7, 2023
Upstream change: intel/tinycbor#238 Says it in the upstream commit message: > Unfortunately, the container's initialization code doesn't exactly > lend itself to making the container const (not even IILE > (Immediately-Invoked Lambda Expression) would help here, due to the > interdependency with len), so the idiomatic solution would be to use > std::as_const()/qAsConst(). > > The former is available from C++17, which we don't require, yet, and > the latter is not available under QT_NO_AS_CONST (the default for Qt > these days), so grab the nettle and implement a t17::as_const() that > switches between a manual implementation of std::as_const and the > real thing, depending on __cpp_lib_as_const. The t17 here mimicks > the qNN (q20::remove_cvref_t/q23::forward_like/etc) mechanism used > in Qt itself for backports, with s/q/t/ because ... _T_inyCbor. > > The t17 implementation is local to tst_encoder.cpp, but can easily > be extracted into a separate header once more users emerge. Task-number: QTBUG-115839 Change-Id: I200ae6abbb6173fa9d4b9964be66501c2145f066 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Qt is defaulting to QT_NO_FOREACH these days, so make sure we integrate nicely with downstream and fix the single Q_FOREACH/foreach user, in tst_encoder.cpp.
Unfortunately, the container's initialization code doesn't exactly lend itself to making the container const (not even IILE (Immediately-Invoked Lambda Expression) would help here, due to the interdependency with
len), so the idiomatic solution would be to use std::as_const()/qAsConst().The former is available from C++17, which we don't require, yet, and the latter is not available under QT_NO_AS_CONST (the default for Qt these days), so grab the nettle and implement a t17::as_const() that switches between a manual implementation of std::as_const and the real thing, depending on __cpp_lib_as_const. The
t17here mimicks the qNN (q20::remove_cvref_t/q23::forward_like/etc) mechanism used in Qt itself for backports, with s/q/t/ because ... _T_inyCbor.The t17 implementation is local to tst_encoder.cpp, but can easily be extracted into a separate header once more users emerge.