brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.4 KiB · a370611 Raw
102 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// <sstream>12 13// template <class charT, class traits, class Allocator>14// void swap(basic_stringbuf<charT, traits, Allocator>& x,15//           basic_stringbuf<charT, traits, Allocator>& y)16//   noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||17//            allocator_traits<allocator_type>::is_always_equal::value);18 19#include <sstream>20#include <cassert>21 22#include "test_macros.h"23 24template <class T>25struct test_alloc {26  using value_type = T;27 28  [[nodiscard]] constexpr T* allocate(std::size_t) { return nullptr; }29  void deallocate(void*, std::size_t) {}30};31 32template <class T>33struct test_alloc_propagate_on_container_swap : test_alloc<T> {34  using propagate_on_container_swap = std::true_type;35};36 37template <class T>38struct test_alloc_is_always_equal : test_alloc<T> {39  using is_always_equal = std::true_type;40};41 42template <class T>43struct test_alloc_propagate_on_container_swap_is_always_equal : test_alloc<T> {44  using propagate_on_container_swap = std::true_type;45  using is_always_equal             = std::true_type;46};47 48template <class T>49struct test_alloc_not_empty : test_alloc<T> {50  bool dummy;51};52 53template <class T>54struct test_alloc_propagate_on_container_swap_not_empty : test_alloc<T> {55  using propagate_on_container_swap = std::true_type;56  bool dummy;57};58 59template <class CharT>60static void test() {61  {62    std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc<CharT>> buf1;63    std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc<CharT>> buf;64    static_assert(noexcept(swap(buf, buf1)));65  }66  {67    std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap<CharT>> buf1;68    std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap<CharT>> buf;69    static_assert(noexcept(swap(buf, buf1)));70  }71  {72    std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_is_always_equal<CharT>> buf1;73    std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_is_always_equal<CharT>> buf;74    static_assert(noexcept(swap(buf, buf1)));75  }76  {77    std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap_is_always_equal<CharT>>78        buf1;79    std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap_is_always_equal<CharT>>80        buf;81    static_assert(noexcept(swap(buf, buf1)));82  }83  {84    std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_not_empty<CharT>> buf1;85    std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_not_empty<CharT>> buf;86    LIBCPP_STATIC_ASSERT(!noexcept(swap(buf, buf1)));87  }88  {89    std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap_not_empty<CharT>> buf1;90    std::basic_stringbuf<CharT, std::char_traits<CharT>, test_alloc_propagate_on_container_swap_not_empty<CharT>> buf;91    static_assert(noexcept(swap(buf, buf1)));92  }93}94 95int main(int, char**) {96  test<char>();97#ifndef TEST_HAS_NO_WIDE_CHARACTERS98  test<wchar_t>();99#endif100  return 0;101}102