Skip to content

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