blob: c4557078fc4f569d850d7241786ffb38498ca64e [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <array>
11
12// template <size_t I, class T, size_t N> T& get(array<T, N>& a);
13
14#include <array>
15#include <cassert>
16
Eric Fiselier02bb4bd2015-07-18 23:56:04 +000017#include "test_macros.h"
18
Dan Albert1d4a1ed2016-05-25 22:36:09 -070019#include "../suppress_array_warnings.h"
Eric Fiselier02bb4bd2015-07-18 23:56:04 +000020
21
22#if TEST_STD_VER > 11
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000023struct S {
24 std::array<int, 3> a;
25 int k;
26 constexpr S() : a{1,2,3}, k(std::get<2>(a)) {}
Eric Fiselier02bb4bd2015-07-18 23:56:04 +000027};
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000028
29constexpr std::array<int, 2> getArr () { return { 3, 4 }; }
30#endif
31
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000032int main()
33{
34 {
35 typedef double T;
36 typedef std::array<T, 3> C;
37 C c = {1, 2, 3.5};
38 std::get<1>(c) = 5.5;
39 assert(c[0] == 1);
40 assert(c[1] == 5.5);
41 assert(c[2] == 3.5);
42 }
Eric Fiselier02bb4bd2015-07-18 23:56:04 +000043#if TEST_STD_VER > 11
Marshall Clow8fc4f5a2013-07-17 18:25:36 +000044 {
45 typedef double T;
46 typedef std::array<T, 3> C;
47 constexpr C c = {1, 2, 3.5};
48 static_assert(std::get<0>(c) == 1, "");
49 static_assert(std::get<1>(c) == 2, "");
50 static_assert(std::get<2>(c) == 3.5, "");
51 }
52 {
53 static_assert(S().k == 3, "");
54 static_assert(std::get<1>(getArr()) == 4, "");
55 }
56#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000057}