[libcxx-commits] [libcxx] [libc++] Avoid constructing additional objects when using map::at (PR #157866)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Sep 17 09:04:02 PDT 2025
================
@@ -1279,11 +1306,15 @@ public:
_LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __tree_.find(__k); }
_LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __tree_.find(__k); }
# if _LIBCPP_STD_VER >= 14
- template <typename _K2, enable_if_t<__is_transparent_v<_Compare, _K2>, int> = 0>
+ template <typename _K2,
+ enable_if_t<__is_transparent_v<_Compare, _K2> || __is_transparently_comparable_v<_Compare, key_type, _K2>,
----------------
ldionne wrote:
This is very confusing as-is. The only reason for passing `_K2` to `__is_transparent_v` seems to be to make it dependent. The right way to achieve that is usually:
```c++
template <class _K2, class _DependentCompare = _Compare, enable_if_t<__is_transparent_v<_DependentCompare>>, ...>
```
If we did that, then we could get rid of the other arguments of `__is_transparent_v`, and that would make this code a lot clearer IMO, since we'd easily understand that `__is_transparent_v` only checks the typedef.
Let's do that as a follow-up refactoring, or as a prerequisite for this patch.
https://github.com/llvm/llvm-project/pull/157866
More information about the libcxx-commits
mailing list