• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <array>
11 
12 // iterator begin();
13 
14 #include <array>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 
19 // std::array is explicitly allowed to be initialized with A a = { init-list };.
20 // Disable the missing braces warning for this reason.
21 #include "disable_missing_braces_warning.h"
22 
23 struct NoDefault {
NoDefaultNoDefault24   NoDefault(int) {}
25 };
26 
27 
main()28 int main()
29 {
30     {
31         typedef double T;
32         typedef std::array<T, 3> C;
33         C c = {1, 2, 3.5};
34         C::iterator i;
35         i = c.begin();
36         assert(*i == 1);
37         assert(&*i == c.data());
38         *i = 5.5;
39         assert(c[0] == 5.5);
40     }
41     {
42       typedef NoDefault T;
43       typedef std::array<T, 0> C;
44       C c = {};
45       C::iterator ib, ie;
46       ib = c.begin();
47       ie = c.end();
48       assert(ib == ie);
49       LIBCPP_ASSERT(ib != nullptr);
50       LIBCPP_ASSERT(ie != nullptr);
51     }
52 }
53