[libcxx-commits] [libcxx] [libc++] Optimize std::swap of locales (PR #209760)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 22 02:25:59 PDT 2026
================
@@ -143,8 +143,14 @@ private:
friend bool has_facet(const locale&) _NOEXCEPT;
template <class _Facet>
friend const _Facet& use_facet(const locale&);
+
+ friend void swap(locale&, locale&);
};
+inline void swap(locale& __lhs, locale& __rhs) {
----------------
frederick-vs-ja wrote:
Also, existence of move functions affects overload resolution ([Godbolt link](https://godbolt.org/z/Gh8EfE6ex)), although there's implementation divergence and I think Clang and GCC are correct.
Now I'm unsure whether move functions would be wanted because (at least for libc++) currently some precondition-free functions assume that a valid `locale` is non-empty.
How about do this in a way not affecting overload resolution? E.g. by
- specializing the `std::swap` function template,
- adding a sufficiently constraint overload for `std::swap`, or
- (infeasible in C++03 mode) using `if constexpr` and some internal trait in `std::swap`.
https://github.com/llvm/llvm-project/pull/209760
More information about the libcxx-commits
mailing list