brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 6347496 Raw
89 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// <deque>12 13// void swap(deque& 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>::is_always_equal::value);19 20// This tests a conforming extension21 22#include <deque>23#include <utility>24#include <cassert>25 26#include "test_macros.h"27#include "MoveOnly.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 allocate(std::size_t);37  void deallocate(void*, unsigned) {}38 39  typedef std::true_type propagate_on_container_swap;40};41 42template <class T>43struct some_alloc2 {44  typedef T value_type;45 46  some_alloc2() {}47  some_alloc2(const some_alloc2&);48  void allocate(std::size_t);49  void deallocate(void*, unsigned) {}50 51  typedef std::false_type propagate_on_container_swap;52  typedef std::true_type is_always_equal;53};54 55int main(int, char**) {56  {57    typedef std::deque<MoveOnly> C;58    static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");59  }60#if defined(_LIBCPP_VERSION)61  {62    typedef std::deque<MoveOnly, test_allocator<MoveOnly>> C;63    static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");64  }65  {66    typedef std::deque<MoveOnly, other_allocator<MoveOnly>> C;67    static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");68  }69#endif // _LIBCPP_VERSION70  {71    typedef std::deque<MoveOnly, some_alloc<MoveOnly>> C;72#if TEST_STD_VER >= 1473    //  In C++14, if POCS is set, swapping the allocator is required not to throw74    static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");75#else76    static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");77#endif78  }79#if TEST_STD_VER >= 1480  {81    typedef std::deque<MoveOnly, some_alloc2<MoveOnly>> C;82    //  if the allocators are always equal, then the swap can be noexcept83    static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");84  }85#endif86 87  return 0;88}89