//===----------------------------------------------------------------------===// // // 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 // // template , class Allocator = allocator > // class basic_stringbuf // void swap(basic_stringbuf& rhs) // noexcept(allocator_traits::propagate_on_container_swap::value || // allocator_traits::is_always_equal::value); #include #include #include "test_macros.h" template struct test_alloc { using value_type = T; [[nodiscard]] constexpr T* allocate(std::size_t) { return nullptr; } void deallocate(void*, std::size_t) {} }; template struct test_alloc_propagate_on_container_swap : test_alloc { using propagate_on_container_swap = std::true_type; }; template struct test_alloc_is_always_equal : test_alloc { using is_always_equal = std::true_type; }; template struct test_alloc_propagate_on_container_swap_is_always_equal : test_alloc { using propagate_on_container_swap = std::true_type; using is_always_equal = std::true_type; }; template struct test_alloc_not_empty : test_alloc { bool dummy; }; template struct test_alloc_propagate_on_container_swap_not_empty : test_alloc { using propagate_on_container_swap = std::true_type; bool dummy; }; template static void test() { { std::basic_stringbuf, test_alloc> buf1; std::basic_stringbuf, test_alloc> buf; static_assert(noexcept(buf.swap(buf1))); } { std::basic_stringbuf, test_alloc_propagate_on_container_swap> buf1; std::basic_stringbuf, test_alloc_propagate_on_container_swap> buf; static_assert(noexcept(buf.swap(buf1))); } { std::basic_stringbuf, test_alloc_is_always_equal> buf1; std::basic_stringbuf, test_alloc_is_always_equal> buf; static_assert(noexcept(buf.swap(buf1))); } { std::basic_stringbuf, test_alloc_propagate_on_container_swap_is_always_equal> buf1; std::basic_stringbuf, test_alloc_propagate_on_container_swap_is_always_equal> buf; static_assert(noexcept(buf.swap(buf1))); } { std::basic_stringbuf, test_alloc_not_empty> buf1; std::basic_stringbuf, test_alloc_not_empty> buf; LIBCPP_STATIC_ASSERT(!noexcept(buf.swap(buf1))); } { std::basic_stringbuf, test_alloc_propagate_on_container_swap_not_empty> buf1; std::basic_stringbuf, test_alloc_propagate_on_container_swap_not_empty> buf; static_assert(noexcept(buf.swap(buf1))); } } int main(int, char**) { test(); #ifndef TEST_HAS_NO_WIDE_CHARACTERS test(); #endif return 0; }