Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix const value return by emplace iterator #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

firedtoad
Copy link

with const this code will not compile
tsl::sparse_map<uint32_t,uint32_t> spp;
const auto it=spp.emplace(1,1);
it.first->second=1;

firedtoad added 3 commits May 23, 2023 00:00
with const this code will not compile
tsl::sparse_map<uint32_t,uint32_t> spp;
const auto it=spp.emplace(1,1);
it.first->second=1;
@Tessil
Copy link
Owner

Tessil commented Oct 9, 2023

Thank you for the contribution, unfortunately casting a std::pair<K, V>& to a std::pair<const K, V>& is an undefined behaviour. See https://stackoverflow.com/questions/8305793/is-it-possible-to-cast-a-pairkey-value-to-a-pairconst-key-value for more information.

@firedtoad
Copy link
Author

firedtoad commented Oct 10, 2023 via email

@firedtoad
Copy link
Author

The new standard shows that it is layout compatible.
https://godbolt.org/z/dKn99YTeM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants