blob: 7b26d231dbdd91e3e9f264e58d98ff4cf4e14fba [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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 Hinnant3e519522010-05-11 19:42:16 +00006//
7//===----------------------------------------------------------------------===//
8
9// <array>
10
11// iterator begin();
12
13#include <array>
14#include <cassert>
15
Louis Dionne7125b082018-12-06 18:24:39 +000016#include "test_macros.h"
17
Eric Fiselierb4e2e7a2015-10-01 07:05:38 +000018// 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 Fiselier2decfad2015-07-18 23:56:04 +000021
Marshall Clowdb499652018-10-12 21:24:44 +000022struct NoDefault {
23 NoDefault(int) {}
24};
25
Eric Fiselier59cdf902018-02-07 21:06:13 +000026
JF Bastien2df59c52019-02-04 20:31:13 +000027int main(int, char**)
Howard Hinnant3e519522010-05-11 19:42:16 +000028{
29 {
30 typedef double T;
31 typedef std::array<T, 3> C;
32 C c = {1, 2, 3.5};
Howard Hinnant27745452011-01-28 23:46:28 +000033 C::iterator i;
34 i = c.begin();
Howard Hinnant3e519522010-05-11 19:42:16 +000035 assert(*i == 1);
36 assert(&*i == c.data());
37 *i = 5.5;
38 assert(c[0] == 5.5);
39 }
Eric Fiselier59cdf902018-02-07 21:06:13 +000040 {
Eric Fiselier59cdf902018-02-07 21:06:13 +000041 typedef NoDefault T;
42 typedef std::array<T, 0> C;
43 C c = {};
Louis Dionne7125b082018-12-06 18:24:39 +000044 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 Fiselier59cdf902018-02-07 21:06:13 +000050 }
JF Bastien2df59c52019-02-04 20:31:13 +000051
52 return 0;
Howard Hinnant3e519522010-05-11 19:42:16 +000053}