[libcxx-commits] [libcxx] [libc++] Remove [[nodiscard]] from map etc. operator[] (PR #172444)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Dec 16 01:29:22 PST 2025
================
@@ -465,13 +465,13 @@ class flat_map {
}
// [flat.map.access], element access
- [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](const key_type& __x)
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 mapped_type& operator[](const key_type& __x)
----------------
frederick-vs-ja wrote:
I'm not sure whether value-discarding `m[k]` is intended. If one only wants the side effects, `m.try_emplace(k)` can be used instead to express this more clearly.
For `map` and `unordered_map`, `m[k]` is possibly a workaround because `try_emplace` wasn't present before C++17. So I just want to keep `[[nodiscard]]` for `flat_map::operator[]`.
https://github.com/llvm/llvm-project/pull/172444
More information about the libcxx-commits
mailing list