[libcxx-commits] [libcxx] WIP - [libc++][strings] P2591R5: Concatenation of strings and string views (PR #88389)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 12 21:21:54 PDT 2024


================
@@ -4005,6 +4023,51 @@ operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) {
 
 #endif // _LIBCPP_CXX03_LANG
 
+#if _LIBCPP_STD_VER >= 26
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
+operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
+          type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) {
+  using _String = basic_string<_CharT, _Traits, _Allocator>;
+
+  _String __r = __lhs;
+  __r.append(__rhs);
+  return __r;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
+operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs,
+          type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) {
+  __lhs.append(__rhs);
+  return std::move(__lhs);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
+operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
+          const basic_string<_CharT, _Traits, _Allocator>& __rhs) {
+  using _String = basic_string<_CharT, _Traits, _Allocator>;
+
+  _String __r{__lhs};
+  __r.append(__rhs);
+  return __r;
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_HIDE_FROM_ABI constexpr basic_string<_CharT, _Traits, _Allocator>
+operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
+          basic_string<_CharT, _Traits, _Allocator>&& __rhs) {
+  using _String = basic_string<_CharT, _Traits, _Allocator>;
+
+  _String __r{__lhs};
+  __r.append(std::move(__rhs));
+  return __r;
----------------
H-G-Hristov wrote:

The original wording doesn't work for our `constexpr_char_traits`. So I did a quick tests to see what happens:
```
constexpr_char_traits.h:105:12: note: comparison between '&__r.__r_.__compressed_pair_elem::__value_.__compressed_pair_elem::union (anonymous union at /include/c++/v1/string:867:5).__compressed_pair_elem::__s.__compressed_pair_elem::__data_[0]' and '&"short"[0]' has unspecified value
# |   105 |     if (s1 < s2)
# |       |            ^
```


https://github.com/llvm/llvm-project/pull/88389


More information about the libcxx-commits mailing list