[libcxx-commits] [libcxx] [libc++] Avoid type-punning between __hash_value_type and pair (PR #143501)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jun 25 08:22:16 PDT 2025
================
@@ -845,6 +861,22 @@ public:
return __emplace_unique(std::forward<_Pp>(__x));
}
+ template <class _ValueT = _Tp, __enable_if_t<__is_hash_value_type<_ValueT>::value, int> = 0>
----------------
ldionne wrote:
As a follow-up refactoring, I would encourage something like this:
```c++
static constexpr bool __is_map_like = __is_hash_value_type<_Tp>::value;
static constexpr bool __is_set_like = !__is_map_like; // if desired
// Then:
template <bool _MapLike = __is_map_like, __enable_if_t<_MapLike, int> = 0>
void __insert_whatever(...) { ... }
template <bool _SetLike = __is_set_like, __enable_if_t<_SetLike, int> = 0>
void __insert_whatever(...) { ... }
```
That is equivalent but IMO easier to understand.
https://github.com/llvm/llvm-project/pull/143501
More information about the libcxx-commits
mailing list