brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 1683191 Raw
92 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++0310 11// <vector>12 13// void swap(vector& c)14//     noexcept(!allocator_type::propagate_on_container_swap::value ||15//              __is_nothrow_swappable<allocator_type>::value);16//17//  In C++17, the standard says that swap shall have:18//     noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||19//              allocator_traits<Allocator>::is_always_equal::value);20 21// This tests a conforming extension22 23#include <vector>24#include <utility>25#include <cassert>26 27#include "test_macros.h"28#include "test_allocator.h"29 30template <class T>31struct some_alloc {32  typedef T value_type;33 34  some_alloc() {}35  some_alloc(const some_alloc&);36  void deallocate(void*, unsigned) {}37 38  typedef std::true_type propagate_on_container_swap;39};40 41template <class T>42struct some_alloc2 {43  typedef T value_type;44 45  some_alloc2() {}46  some_alloc2(const some_alloc2&);47  void deallocate(void*, unsigned) {}48 49  typedef std::false_type propagate_on_container_swap;50  typedef std::true_type is_always_equal;51};52 53int main(int, char**) {54#if defined(_LIBCPP_VERSION)55  {56    typedef std::vector<bool> C;57    static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");58  }59  {60    typedef std::vector<bool, test_allocator<bool>> C;61    static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");62  }63  {64    typedef std::vector<bool, other_allocator<bool>> C;65    static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");66  }67#endif // _LIBCPP_VERSION68  {69#if TEST_STD_VER >= 1470#  if defined(_LIBCPP_VERSION)71    //  In C++14, if POCS is set, swapping the allocator is required not to throw72    typedef std::vector<bool, some_alloc<bool>> C;73    static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");74#  endif // _LIBCPP_VERSION75#else76    typedef std::vector<bool, some_alloc<bool>> C;77    static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");78#endif79  }80#if TEST_STD_VER >= 1481#  if defined(_LIBCPP_VERSION)82  {83    typedef std::vector<bool, some_alloc2<bool>> C;84    //  if the allocators are always equal, then the swap can be noexcept85    static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");86  }87#  endif // _LIBCPP_VERSION88#endif89 90  return 0;91}92