CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
84 lines
1.8 KiB
ReStructuredText
84 lines
1.8 KiB
ReStructuredText
.. title:: clang-tidy - modernize-use-structured-binding
|
|
|
|
modernize-use-structured-binding
|
|
================================
|
|
|
|
Finds places where structured bindings could be used to decompose pairs and
|
|
suggests replacing them.
|
|
|
|
This check finds three code patterns and recommends using structured bindings
|
|
for clearer, more idiomatic C++17 code.
|
|
|
|
1. Decompose a pair variable by assigning its members to separate variables
|
|
right after its definition:
|
|
|
|
.. code-block:: c++
|
|
|
|
auto p = getPair<int, int>();
|
|
int x = p.first;
|
|
int y = p.second;
|
|
|
|
into:
|
|
|
|
auto [x, y] = getPair<int, int>();
|
|
|
|
2. Use ``std::tie`` to decompose a pair into two predefined variables:
|
|
|
|
.. code-block:: c++
|
|
|
|
int a;
|
|
int b;
|
|
std::tie(a, b) = getPair<int, int>();
|
|
|
|
into:
|
|
|
|
auto [a, b] = getPair<int, int>();
|
|
|
|
3. Manually decompose a pair by assigning to its members to local variables
|
|
in a range-based for loop:
|
|
|
|
.. code-block:: c++
|
|
|
|
for (auto p : vecOfPairs) {
|
|
int x = p.first;
|
|
int y = p.second;
|
|
// ...
|
|
}
|
|
|
|
into:
|
|
|
|
for (auto [x, y] : vecOfPairs) {
|
|
// use x and y
|
|
}
|
|
|
|
Limitations
|
|
-----------
|
|
|
|
The check currently ignores variables defined with attributes or qualifiers
|
|
except ``const`` and ``&`` since it's not very common:
|
|
|
|
.. code-block:: c++
|
|
|
|
static auto pair = getPair();
|
|
static int b = pair.first;
|
|
static int c = pair.second;
|
|
|
|
The check doesn't handle some situations which could possibly be transferred
|
|
to structured bindings, for example:
|
|
|
|
.. code-block:: c++
|
|
|
|
const auto& results = mapping.try_emplace("hello!");
|
|
const iterator& it = results.first;
|
|
bool succeed = results.second;
|
|
// succeed is not changed in the following code
|
|
|
|
and:
|
|
|
|
.. code-block:: c++
|
|
|
|
const auto results = mapping.try_emplace("hello!");
|
|
if (results.second) {
|
|
handle_inserted(results.first);
|
|
}
|