Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <array> |
| 10 | |
| 11 | // iterator begin(); |
| 12 | |
| 13 | #include <array> |
| 14 | #include <cassert> |
| 15 | |
Louis Dionne | 7125b08 | 2018-12-06 18:24:39 +0000 | [diff] [blame] | 16 | #include "test_macros.h" |
| 17 | |
Eric Fiselier | b4e2e7a | 2015-10-01 07:05:38 +0000 | [diff] [blame] | 18 | // std::array is explicitly allowed to be initialized with A a = { init-list };. |
| 19 | // Disable the missing braces warning for this reason. |
| 20 | #include "disable_missing_braces_warning.h" |
Eric Fiselier | 2decfad | 2015-07-18 23:56:04 +0000 | [diff] [blame] | 21 | |
Marshall Clow | db49965 | 2018-10-12 21:24:44 +0000 | [diff] [blame] | 22 | struct NoDefault { |
| 23 | NoDefault(int) {} |
| 24 | }; |
| 25 | |
Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 26 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 27 | int main(int, char**) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 28 | { |
| 29 | { |
| 30 | typedef double T; |
| 31 | typedef std::array<T, 3> C; |
| 32 | C c = {1, 2, 3.5}; |
Howard Hinnant | 2774545 | 2011-01-28 23:46:28 +0000 | [diff] [blame] | 33 | C::iterator i; |
| 34 | i = c.begin(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | assert(*i == 1); |
| 36 | assert(&*i == c.data()); |
| 37 | *i = 5.5; |
| 38 | assert(c[0] == 5.5); |
| 39 | } |
Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 40 | { |
Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 41 | typedef NoDefault T; |
| 42 | typedef std::array<T, 0> C; |
| 43 | C c = {}; |
Louis Dionne | 7125b08 | 2018-12-06 18:24:39 +0000 | [diff] [blame] | 44 | C::iterator ib, ie; |
| 45 | ib = c.begin(); |
| 46 | ie = c.end(); |
| 47 | assert(ib == ie); |
| 48 | LIBCPP_ASSERT(ib != nullptr); |
| 49 | LIBCPP_ASSERT(ie != nullptr); |
Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 50 | } |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 51 | |
| 52 | return 0; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 53 | } |