xref: /llvm-project/libcxx/test/std/containers/sequences/array/max_size.pass.cpp (revision 77b9abfc8e89ca627e4f9a1cc206bea131db6db1)
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 // <array>
10 
11 // class array
12 
13 // constexpr bool max_size() const noexcept;
14 
15 #include <array>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 
tests()20 TEST_CONSTEXPR_CXX14 bool tests()
21 {
22     {
23         typedef std::array<int, 2> C;
24         C c = {};
25         ASSERT_NOEXCEPT(c.max_size());
26         assert(c.max_size() == 2);
27     }
28     {
29         typedef std::array<int, 0> C;
30         C c = {};
31         ASSERT_NOEXCEPT(c.max_size());
32         assert(c.max_size() == 0);
33     }
34 
35     return true;
36 }
37 
main(int,char **)38 int main(int, char**)
39 {
40     tests();
41 #if TEST_STD_VER >= 14
42     static_assert(tests(), "");
43 #endif
44 
45 #if TEST_STD_VER >= 11
46     // Sanity check for constexpr in C++11
47     {
48         constexpr std::array<int, 3> array = {};
49         static_assert(array.max_size() == 3, "");
50     }
51 #endif
52 
53     return 0;
54 }
55