| 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-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// <forward_list> |
| 10 |
|
| 11 |
// forward_list(const forward_list& x); |
| 12 |
|
| 13 |
#include <forward_list> |
| 14 |
#include <cassert> |
| 15 |
#include <iterator> |
| 16 |
|
| 17 |
#include "test_macros.h" |
| 18 |
#include "test_allocator.h" |
| 19 |
#include "min_allocator.h" |
| 20 |
|
| 21 |
int main(int, char**) |
| 22 |
{ |
| 23 |
{ |
| 24 |
typedef int T; |
| 25 |
typedef test_allocator<int> A; |
| 26 |
typedef std::forward_list<T, A> C; |
| 27 |
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 28 |
C c0(std::begin(t), std::end(t), A(10)); |
| 29 |
C c = c0; |
| 30 |
int n = 0; |
| 31 |
for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) |
| 32 |
assert(*i == n); |
| 33 |
assert(n == std::end(t) - std::begin(t)); |
| 34 |
assert(c == c0); |
| 35 |
assert(c.get_allocator() == A(10)); |
| 36 |
} |
| 37 |
#if TEST_STD_VER >= 11 |
| 38 |
{ |
| 39 |
typedef int T; |
| 40 |
typedef other_allocator<int> A; |
| 41 |
typedef std::forward_list<T, A> C; |
| 42 |
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 43 |
C c0(std::begin(t), std::end(t), A(10)); |
| 44 |
C c = c0; |
| 45 |
int n = 0; |
| 46 |
for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) |
| 47 |
assert(*i == n); |
| 48 |
assert(n == std::end(t) - std::begin(t)); |
| 49 |
assert(c == c0); |
| 50 |
assert(c.get_allocator() == A(-2)); |
| 51 |
} |
| 52 |
{ |
| 53 |
typedef int T; |
| 54 |
typedef min_allocator<int> A; |
| 55 |
typedef std::forward_list<T, A> C; |
| 56 |
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 57 |
C c0(std::begin(t), std::end(t), A()); |
| 58 |
C c = c0; |
| 59 |
int n = 0; |
| 60 |
for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) |
| 61 |
assert(*i == n); |
| 62 |
assert(n == std::end(t) - std::begin(t)); |
| 63 |
assert(c == c0); |
| 64 |
assert(c.get_allocator() == A()); |
| 65 |
} |
| 66 |
#endif |
| 67 |
|
| 68 |
return 0; |
| 69 |
} |