1e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow//===----------------------------------------------------------------------===//
2e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow//
3e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow//                     The LLVM Compiler Infrastructure
4e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow//
5e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow// This file is dual licensed under the MIT and the University of Illinois Open
6e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow// Source Licenses. See LICENSE.TXT for details.
7e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow//
8e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow//===----------------------------------------------------------------------===//
9e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow
105cb52824fc2a0caf233311e91d9a2a53368f04adDan Albert// UNSUPPORTED: c++98, c++03, c++11
115cb52824fc2a0caf233311e91d9a2a53368f04adDan Albert
12e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow#include <tuple>
13e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow#include <string>
14e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow#include <complex>
15e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow
16e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow#include <cassert>
17e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow
18e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clowint main()
19e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow{
20e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow#if _LIBCPP_STD_VER > 11
21e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    typedef std::complex<float> cf;
22e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    {
23e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    auto t1 = std::tuple<int, std::string, cf> { 42, "Hi", { 1,2 }};
24e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    assert ( std::get<int>(t1) == 42 ); // find at the beginning
25e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    assert ( std::get<std::string>(t1) == "Hi" ); // find in the middle
26e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    assert ( std::get<cf>(t1).real() == 1 ); // find at the end
27e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    assert ( std::get<cf>(t1).imag() == 2 );
28e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    }
29e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow
30e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    {
31e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    auto t2 = std::tuple<int, std::string, int, cf> { 42, "Hi", 23, { 1,2 }};
32e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow//  get<int> would fail!
33e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    assert ( std::get<std::string>(t2) == "Hi" );
34e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    assert (( std::get<cf>(t2) == cf{ 1,2 } ));
35e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    }
36e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow
37e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    {
38da0a0e8a1be285d18870955cffc1b51982675dd8Marshall Clow    constexpr std::tuple<int, const int, double, double> p5 { 1, 2, 3.4, 5.6 };
39da0a0e8a1be285d18870955cffc1b51982675dd8Marshall Clow    static_assert ( std::get<int>(p5) == 1, "" );
40da0a0e8a1be285d18870955cffc1b51982675dd8Marshall Clow    static_assert ( std::get<const int>(p5) == 2, "" );
41da0a0e8a1be285d18870955cffc1b51982675dd8Marshall Clow    }
42da0a0e8a1be285d18870955cffc1b51982675dd8Marshall Clow
43da0a0e8a1be285d18870955cffc1b51982675dd8Marshall Clow    {
44e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    const std::tuple<int, const int, double, double> p5 { 1, 2, 3.4, 5.6 };
45e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    const int &i1 = std::get<int>(p5);
46e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    const int &i2 = std::get<const int>(p5);
47e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    assert ( i1 == 1 );
48e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    assert ( i2 == 2 );
49e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    }
50e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow
51e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    {
52e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    typedef std::unique_ptr<int> upint;
53e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    std::tuple<upint> t(upint(new int(4)));
54e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    upint p = std::get<upint>(std::move(t)); // get rvalue
55e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    assert(*p == 4);
56e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    assert(std::get<0>(t) == nullptr); // has been moved from
57e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow    }
58e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow
59e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow#endif
60e8029e54f1c7cb1f758ef19edb7745fa382fe96cMarshall Clow}
61