brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · b76c195 Raw
158 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <tuple>10 11// template <class... Types> class tuple;12 13// template <class... UTypes> tuple(const tuple<UTypes...>& u);14 15// UNSUPPORTED: c++0316 17#include <tuple>18#include <utility>19#include <string>20#include <cassert>21 22#include "test_macros.h"23 24struct Explicit {25  int value;26  explicit Explicit(int x) : value(x) {}27};28 29struct Implicit {30  int value;31  Implicit(int x) : value(x) {}32};33 34struct ExplicitTwo {35    ExplicitTwo() {}36    ExplicitTwo(ExplicitTwo const&) {}37    ExplicitTwo(ExplicitTwo &&) {}38 39    template <class T, class = typename std::enable_if<!std::is_same<T, ExplicitTwo>::value>::type>40    explicit ExplicitTwo(T) {}41};42 43struct B44{45    int id_;46 47    explicit B(int i) : id_(i) {}48};49 50struct D51    : B52{53    explicit D(int i) : B(i) {}54};55 56#if TEST_STD_VER > 1157 58struct A59{60    int id_;61 62    constexpr A(int i) : id_(i) {}63    friend constexpr bool operator==(const A& x, const A& y) {return x.id_ == y.id_;}64};65 66struct C67{68    int id_;69 70    constexpr explicit C(int i) : id_(i) {}71    friend constexpr bool operator==(const C& x, const C& y) {return x.id_ == y.id_;}72};73 74#endif75 76int main(int, char**)77{78    {79        typedef std::tuple<long> T0;80        typedef std::tuple<long long> T1;81        T0 t0(2);82        T1 t1 = t0;83        assert(std::get<0>(t1) == 2);84    }85#if TEST_STD_VER > 1186    {87        typedef std::tuple<int> T0;88        typedef std::tuple<A> T1;89        constexpr T0 t0(2);90        constexpr T1 t1 = t0;91        static_assert(std::get<0>(t1) == 2, "");92    }93    {94        typedef std::tuple<int> T0;95        typedef std::tuple<C> T1;96        constexpr T0 t0(2);97        constexpr T1 t1{t0};98        static_assert(std::get<0>(t1) == C(2), "");99    }100#endif101    {102        typedef std::tuple<long, char> T0;103        typedef std::tuple<long long, int> T1;104        T0 t0(2, 'a');105        T1 t1 = t0;106        assert(std::get<0>(t1) == 2);107        assert(std::get<1>(t1) == int('a'));108    }109    {110        typedef std::tuple<long, char, D> T0;111        typedef std::tuple<long long, int, B> T1;112        T0 t0(2, 'a', D(3));113        T1 t1 = t0;114        assert(std::get<0>(t1) == 2);115        assert(std::get<1>(t1) == int('a'));116        assert(std::get<2>(t1).id_ == 3);117    }118    {119        D d(3);120        typedef std::tuple<long, char, D&> T0;121        typedef std::tuple<long long, int, B&> T1;122        T0 t0(2, 'a', d);123        T1 t1 = t0;124        d.id_ = 2;125        assert(std::get<0>(t1) == 2);126        assert(std::get<1>(t1) == int('a'));127        assert(std::get<2>(t1).id_ == 2);128    }129    {130        typedef std::tuple<long, char, int> T0;131        typedef std::tuple<long long, int, B> T1;132        T0 t0(2, 'a', 3);133        T1 t1(t0);134        assert(std::get<0>(t1) == 2);135        assert(std::get<1>(t1) == int('a'));136        assert(std::get<2>(t1).id_ == 3);137    }138    {139        const std::tuple<int> t1(42);140        std::tuple<Explicit> t2(t1);141        assert(std::get<0>(t2).value == 42);142    }143    {144        const std::tuple<int> t1(42);145        std::tuple<Implicit> t2 = t1;146        assert(std::get<0>(t2).value == 42);147    }148    {149        static_assert(std::is_convertible<ExplicitTwo&&, ExplicitTwo>::value, "");150        static_assert(std::is_convertible<std::tuple<ExplicitTwo&&>&&, const std::tuple<ExplicitTwo>&>::value, "");151 152        ExplicitTwo e;153        std::tuple<ExplicitTwo> t = std::tuple<ExplicitTwo&&>(std::move(e));154        ((void)t);155    }156  return 0;157}158