Skip to content

Conversation

@jl-wynen
Copy link
Member

Fixes #3639

namespace {
Masks masks_not_in_dim(const Masks &all_masks, const Dim dim) {
Masks results;
for (auto [name, mask] : all_masks) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto [name, mask] : all_masks) {
for (auto &&[name, mask] : all_masks) {

Copy link
Member Author

@jl-wynen jl-wynen Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes no difference because the iterator returns pairs of references:
without-ref
with-ref

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then my understanding of auto must be rusty, I thought auto x = f() never resolves to a reference?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't. Here, f() returns a pair of references. auto doesn't deduce to a ref for the pair itself. But it preserves the refs of the pairs contents. Have a look at this:

#include <iostream>
#include <functional>
#include <utility>

std::pair<int, int&> f(int &x) {
    return std::pair{0, std::ref(x)};
}

int main() {
    int x = 2;
    auto [_, y] = f(x);
    y = -1;
    std::cout << x << '\n';
}

This prints -1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jl-wynen jl-wynen merged commit 17a7699 into main Feb 21, 2025
@jl-wynen jl-wynen deleted the scale-drop-applied-masks branch February 21, 2025 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Masks on lookup propagate to other operand?

4 participants