| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
|
| 3 |
#include <iterator> |
| 4 |
|
| 5 |
template<typename T, bool Nothrow> |
| 6 |
struct bidi |
| 7 |
{ |
| 8 |
using value_type = T; |
| 9 |
using pointer = T*; |
| 10 |
using reference = T&; |
| 11 |
using difference_type = std::ptrdiff_t; |
| 12 |
using iterator_category = std::bidirectional_iterator_tag; |
| 13 |
|
| 14 |
T* ptr; |
| 15 |
|
| 16 |
bidi(T* ptr = nullptr) noexcept(Nothrow) : ptr(ptr) { } |
| 17 |
|
| 18 |
bidi(const bidi& iter) noexcept(Nothrow) : ptr(iter.ptr) { } |
| 19 |
|
| 20 |
template<typename U> |
| 21 |
bidi(const bidi<U, Nothrow>& iter) noexcept(Nothrow) : ptr(iter.ptr) { } |
| 22 |
|
| 23 |
bidi& operator=(const bidi& iter) noexcept(Nothrow) |
| 24 |
{ |
| 25 |
ptr = iter.ptr; |
| 26 |
return *this; |
| 27 |
} |
| 28 |
|
| 29 |
template<typename U> |
| 30 |
bidi& operator=(const bidi<U, Nothrow>& iter) noexcept(Nothrow) |
| 31 |
{ |
| 32 |
ptr = iter.ptr; |
| 33 |
return *this; |
| 34 |
} |
| 35 |
|
| 36 |
bidi& operator++() { ++ptr; return *this; } |
| 37 |
bidi& operator--() { --ptr; return *this; } |
| 38 |
bidi operator++(int) { bidi tmp = *this; ++ptr; return tmp; } |
| 39 |
bidi operator--(int) { bidi tmp = *this; --ptr; return tmp; } |
| 40 |
|
| 41 |
reference operator*() const { return *ptr; } |
| 42 |
pointer operator->() const { return ptr; } |
| 43 |
}; |
| 44 |
|
| 45 |
void |
| 46 |
test01() |
| 47 |
{ |
| 48 |
using B1 = bidi<int, true>; |
| 49 |
using R1 = std::reverse_iterator<B1>; |
| 50 |
static_assert( std::is_nothrow_default_constructible<R1>(), "" ); |
| 51 |
static_assert( std::is_nothrow_copy_constructible<R1>(), "" ); |
| 52 |
static_assert( std::is_nothrow_move_constructible<R1>(), "" ); |
| 53 |
static_assert( std::is_nothrow_copy_assignable<R1>(), "" ); |
| 54 |
static_assert( std::is_nothrow_move_assignable<R1>(), "" ); |
| 55 |
static_assert( std::is_nothrow_constructible<R1, const B1&>(), "" ); |
| 56 |
static_assert( std::is_nothrow_constructible<R1, B1>(), "" ); |
| 57 |
|
| 58 |
using B2 = bidi<const int, true>; |
| 59 |
using R2 = std::reverse_iterator<B2>; |
| 60 |
// Test conversions from reverse_iterator<B1> to reverse_iterator<B2>. |
| 61 |
static_assert( std::is_nothrow_constructible<R2, const R1&>(), "" ); |
| 62 |
static_assert( std::is_nothrow_assignable<R2&, const R1&>(), "" ); |
| 63 |
// And from B1 to reverse_iterator<B2>. |
| 64 |
static_assert( std::is_nothrow_constructible<R2, const B2&>(), "" ); |
| 65 |
static_assert( std::is_nothrow_constructible<R2, B2>(), "" ); |
| 66 |
static_assert( std::is_nothrow_constructible<R2, const B1&>(), "" ); |
| 67 |
static_assert( std::is_nothrow_constructible<R2, B1>(), "" ); |
| 68 |
|
| 69 |
using B3 = bidi<int, false>; |
| 70 |
using R3 = std::reverse_iterator<B3>; |
| 71 |
static_assert( ! std::is_nothrow_default_constructible<R3>(), "" ); |
| 72 |
static_assert( ! std::is_nothrow_copy_constructible<R3>(), "" ); |
| 73 |
static_assert( ! std::is_nothrow_move_constructible<R3>(), "" ); |
| 74 |
static_assert( ! std::is_nothrow_copy_assignable<R3>(), "" ); |
| 75 |
static_assert( ! std::is_nothrow_move_assignable<R3>(), "" ); |
| 76 |
static_assert( ! std::is_nothrow_constructible<R3, const B3&>(), "" ); |
| 77 |
static_assert( ! std::is_nothrow_constructible<R3, B3>(), "" ); |
| 78 |
|
| 79 |
using B4 = bidi<const int, false>; |
| 80 |
using R4 = std::reverse_iterator<B4>; |
| 81 |
// Test conversions from reverse_iterator<B3> to reverse_iterator<B4>. |
| 82 |
static_assert( ! std::is_nothrow_constructible<R4, const R3&>(), "" ); |
| 83 |
static_assert( ! std::is_nothrow_assignable<R4&, const R3&>(), "" ); |
| 84 |
// And from B3 to reverse_iterator<B4>. |
| 85 |
static_assert( ! std::is_nothrow_constructible<R4, const B4&>(), "" ); |
| 86 |
static_assert( ! std::is_nothrow_constructible<R4, B4>(), "" ); |
| 87 |
static_assert( ! std::is_nothrow_constructible<R4, const B3&>(), "" ); |
| 88 |
static_assert( ! std::is_nothrow_constructible<R4, B3>(), "" ); |
| 89 |
|
| 90 |
static_assert( noexcept(std::declval<R1&>().base()), "" ); |
| 91 |
static_assert( ! noexcept(std::declval<R3&>().base()), "" ); |
| 92 |
} |