|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// Part of the libcu++ 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 | +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +// UNSUPPORTED: nvrtc |
| 11 | + |
| 12 | +#include <cuda/std/cassert> |
| 13 | +#include <cuda/std/tuple> |
| 14 | + |
| 15 | +#include <complex> |
| 16 | +#include <tuple> |
| 17 | +#include <utility> |
| 18 | + |
| 19 | +#include "test_macros.h" |
| 20 | + |
| 21 | +template <class STD_TYPE, size_t Index, typename Expected> |
| 22 | +__host__ __device__ constexpr void test() |
| 23 | +{ |
| 24 | + static_assert(cuda::std::is_same_v<cuda::std::tuple_element_t<Index, STD_TYPE>, Expected>); |
| 25 | + static_assert(cuda::std::is_same_v<cuda::std::tuple_element_t<Index, const STD_TYPE>, const Expected>); |
| 26 | + static_assert(cuda::std::is_same_v<cuda::std::tuple_element_t<Index, volatile STD_TYPE>, volatile Expected>); |
| 27 | + static_assert( |
| 28 | + cuda::std::is_same_v<cuda::std::tuple_element_t<Index, const volatile STD_TYPE>, const volatile Expected>); |
| 29 | +} |
| 30 | + |
| 31 | +__host__ __device__ constexpr bool test() |
| 32 | +{ |
| 33 | + test<::std::pair<int, float>, 0, int>(); |
| 34 | + test<::std::pair<int, float>, 1, float>(); |
| 35 | + |
| 36 | + // tuple has the size of the number of template arguments |
| 37 | + test<::std::tuple<int>, 0, int>(); |
| 38 | + test<::std::tuple<int, float>, 0, int>(); |
| 39 | + test<::std::tuple<int, float>, 1, float>(); |
| 40 | + test<::std::tuple<int, float, short>, 0, int>(); |
| 41 | + test<::std::tuple<int, float, short>, 1, float>(); |
| 42 | + test<::std::tuple<int, float, short>, 2, short>(); |
| 43 | + |
| 44 | + // array has always the same element |
| 45 | + test<::std::array<int, 4>, 0, int>(); |
| 46 | + test<::std::array<int, 4>, 1, int>(); |
| 47 | + test<::std::array<int, 4>, 2, int>(); |
| 48 | + test<::std::array<int, 4>, 3, int>(); |
| 49 | + |
| 50 | + return true; |
| 51 | +} |
| 52 | + |
| 53 | +int main(int arg, char** argv) |
| 54 | +{ |
| 55 | + test(); |
| 56 | + static_assert(test()); |
| 57 | + return 0; |
| 58 | +} |
0 commit comments