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// <tuple>
10
11// template <class... Types> class tuple;
12
13// template <size_t I, class... Types>
14// typename tuple_element<I, tuple<Types...> >::type const&
15// get(const tuple<Types...>& t);
16
17// UNSUPPORTED: c++03
18
19#include <tuple>
20#include <string>
21#include <cassert>
22
23#include "test_macros.h"
24
25struct Empty {};
26
27int main(int, char**)
28{
29 {
30 typedef std::tuple<int> T;
31 const T t(3);
32 assert(std::get<0>(t) == 3);
33 }
34 {
35 typedef std::tuple<std::string, int> T;
36 const T t("high", 5);
37 assert(std::get<0>(t) == "high");
38 assert(std::get<1>(t) == 5);
39 }
40#if TEST_STD_VER > 11
41 {
42 typedef std::tuple<double, int> T;
43 constexpr T t(2.718, 5);
44 static_assert(std::get<0>(t) == 2.718, "");
45 static_assert(std::get<1>(t) == 5, "");
46 }
47 {
48 typedef std::tuple<Empty> T;
49 constexpr T t{Empty()};
50 constexpr Empty e = std::get<0>(t);
51 ((void)e); // Prevent unused warning
52 }
53#endif
54 {
55 typedef std::tuple<double&, std::string, int> T;
56 double d = 1.5;
57 const T t(d, "high", 5);
58 assert(std::get<0>(t) == 1.5);
59 assert(std::get<1>(t) == "high");
60 assert(std::get<2>(t) == 5);
61 std::get<0>(t) = 2.5;
62 assert(std::get<0>(t) == 2.5);
63 assert(std::get<1>(t) == "high");
64 assert(std::get<2>(t) == 5);
65 assert(d == 2.5);
66 }
67
68 return 0;
69}
70

source code of libcxx/test/std/utilities/tuple/tuple.tuple/tuple.elem/get_const.pass.cpp