// [stringbuf.assign] Assign and swap:
basic_stringbuf& operator=(basic_stringbuf&& rhs);
- void swap(basic_stringbuf& rhs);
+ void swap(basic_stringbuf& rhs) noexcept(see below); // conditionally noexcept since C++20
// [stringbuf.members] Member functions:
basic_string<char_type, traits_type, allocator_type> str() const;
// [stringbuf.assign] non member swap
template <class charT, class traits, class Allocator>
- void swap(basic_stringbuf<charT, traits, Allocator>& x,
- basic_stringbuf<charT, traits, Allocator>& y);
+void swap(basic_stringbuf<charT, traits, Allocator>& x,
+ basic_stringbuf<charT, traits, Allocator>& y); // conditionally noexcept since C++20
typedef basic_stringbuf<char> stringbuf;
typedef basic_stringbuf<wchar_t> wstringbuf;
};
template <class charT, class traits, class Allocator>
- void swap(basic_istringstream<charT, traits, Allocator>& x,
- basic_istringstream<charT, traits, Allocator>& y);
+void swap(basic_istringstream<charT, traits, Allocator>& x,
+ basic_istringstream<charT, traits, Allocator>& y);
typedef basic_istringstream<char> istringstream;
typedef basic_istringstream<wchar_t> wistringstream;
};
template <class charT, class traits, class Allocator>
- void swap(basic_ostringstream<charT, traits, Allocator>& x,
- basic_ostringstream<charT, traits, Allocator>& y);
+void swap(basic_ostringstream<charT, traits, Allocator>& x,
+ basic_ostringstream<charT, traits, Allocator>& y);
typedef basic_ostringstream<char> ostringstream;
typedef basic_ostringstream<wchar_t> wostringstream;
};
template <class charT, class traits, class Allocator>
- void swap(basic_stringstream<charT, traits, Allocator>& x,
- basic_stringstream<charT, traits, Allocator>& y);
+void swap(basic_stringstream<charT, traits, Allocator>& x,
+ basic_stringstream<charT, traits, Allocator>& y);
typedef basic_stringstream<char> stringstream;
typedef basic_stringstream<wchar_t> wstringstream;
// [stringbuf.assign] Assign and swap:
basic_stringbuf& operator=(basic_stringbuf&& __rhs);
- void swap(basic_stringbuf& __rhs);
+ void swap(basic_stringbuf& __rhs)
+#if _LIBCPP_STD_VER >= 20
+ noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
+ allocator_traits<allocator_type>::is_always_equal::value)
+#endif
+ ;
// [stringbuf.members] Member functions:
string_type str() const;
template <class _CharT, class _Traits, class _Allocator>
void
basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs)
+#if _LIBCPP_STD_VER >= 20
+ noexcept(allocator_traits<_Allocator>::propagate_on_container_swap::value ||
+ allocator_traits<_Allocator>::is_always_equal::value)
+#endif
{
char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
ptrdiff_t __rbinp = -1;
void
swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x,
basic_stringbuf<_CharT, _Traits, _Allocator>& __y)
+#if _LIBCPP_STD_VER >= 20
+ noexcept(noexcept(__x.swap(__y)))
+#endif
{
__x.swap(__y);
}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// <sstream>
+
+// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
+// class basic_stringbuf
+
+// void swap(basic_stringbuf& rhs)
+// noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
+// allocator_traits<allocator_type>::is_always_equal::value);
+
+#include <sstream>
+#include <cassert>
+
+#include "test_macros.h"
+
+template <class T>
+struct test_alloc {
+ using value_type = T;
+
+ [[nodiscard]] constexpr T* allocate(std::size_t) { return nullptr; }
+ void deallocate(void*, unsigned) {}
+};
+
+template <class T>
+struct test_alloc_propagate_on_container_swap : test_alloc<T> {
+ using propagate_on_container_swap = std::true_type;
+};
+
+template <class T>
+struct test_alloc_is_always_equal : test_alloc<T> {
+ using is_always_equal = std::true_type;
+};
+
+template <class T>
+struct test_alloc_propagate_on_container_swap_is_always_equal : test_alloc<T> {
+ using propagate_on_container_swap = std::true_type;
+ using is_always_equal = std::true_type;
+};
+
+template <class T>
+struct test_alloc_not_empty : test_alloc<T> {
+ bool dummy;
+};
+
+template <class T>
+struct test_alloc_propagate_on_container_swap_not_empty : test_alloc<T> {
+ using propagate_on_container_swap = std::true_type;
+ bool dummy;
+};
+
+template <class CharT>
+static void test() {
+ {
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc<CharT>> buf1;
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc<CharT>> buf;
+ static_assert(noexcept(buf.swap(buf1)));
+ }
+ {
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap<CharT>> buf1;
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap<CharT>> buf;
+ static_assert(noexcept(buf.swap(buf1)));
+ }
+ {
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_is_always_equal<CharT>> buf1;
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_is_always_equal<CharT>> buf;
+ static_assert(noexcept(buf.swap(buf1)));
+ }
+ {
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap_is_always_equal<CharT>>
+ buf1;
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap_is_always_equal<CharT>>
+ buf;
+ static_assert(noexcept(buf.swap(buf1)));
+ }
+ {
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_not_empty<CharT>> buf1;
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_not_empty<CharT>> buf;
+ static_assert(!noexcept(buf.swap(buf1)));
+ }
+ {
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap_not_empty<CharT>> buf1;
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap_not_empty<CharT>> buf;
+ static_assert(noexcept(buf.swap(buf1)));
+ }
+}
+
+int main(int, char**) {
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test<wchar_t>();
+#endif
+ return 0;
+}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// <sstream>
+
+// template <class charT, class traits, class Allocator>
+// void swap(basic_stringbuf<charT, traits, Allocator>& x,
+// basic_stringbuf<charT, traits, Allocator>& y)
+// noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
+// allocator_traits<allocator_type>::is_always_equal::value);
+
+#include <sstream>
+#include <cassert>
+
+#include "test_macros.h"
+
+template <class T>
+struct test_alloc {
+ using value_type = T;
+
+ [[nodiscard]] constexpr T* allocate(std::size_t) { return nullptr; }
+ void deallocate(void*, unsigned) {}
+};
+
+template <class T>
+struct test_alloc_propagate_on_container_swap : test_alloc<T> {
+ using propagate_on_container_swap = std::true_type;
+};
+
+template <class T>
+struct test_alloc_is_always_equal : test_alloc<T> {
+ using is_always_equal = std::true_type;
+};
+
+template <class T>
+struct test_alloc_propagate_on_container_swap_is_always_equal : test_alloc<T> {
+ using propagate_on_container_swap = std::true_type;
+ using is_always_equal = std::true_type;
+};
+
+template <class T>
+struct test_alloc_not_empty : test_alloc<T> {
+ bool dummy;
+};
+
+template <class T>
+struct test_alloc_propagate_on_container_swap_not_empty : test_alloc<T> {
+ using propagate_on_container_swap = std::true_type;
+ bool dummy;
+};
+
+template <class CharT>
+static void test() {
+ {
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc<CharT>> buf1;
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc<CharT>> buf;
+ static_assert(noexcept(swap(buf, buf1)));
+ }
+ {
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap<CharT>> buf1;
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap<CharT>> buf;
+ static_assert(noexcept(swap(buf, buf1)));
+ }
+ {
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_is_always_equal<CharT>> buf1;
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_is_always_equal<CharT>> buf;
+ static_assert(noexcept(swap(buf, buf1)));
+ }
+ {
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap_is_always_equal<CharT>>
+ buf1;
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap_is_always_equal<CharT>>
+ buf;
+ static_assert(noexcept(swap(buf, buf1)));
+ }
+ {
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_not_empty<CharT>> buf1;
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_not_empty<CharT>> buf;
+ static_assert(!noexcept(swap(buf, buf1)));
+ }
+ {
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap_not_empty<CharT>> buf1;
+ std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap_not_empty<CharT>> buf;
+ static_assert(noexcept(swap(buf, buf1)));
+ }
+}
+
+int main(int, char**) {
+ test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+ test<wchar_t>();
+#endif
+ return 0;
+}