| 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 | // UNSUPPORTED: c++03, c++11 |
| 10 | // <utility> |
| 11 | |
| 12 | // class make_integer_sequence |
| 13 | |
| 14 | #include <tuple> |
| 15 | #include <utility> |
| 16 | #include <type_traits> |
| 17 | #include <cassert> |
| 18 | |
| 19 | #include "test_macros.h" |
| 20 | |
| 21 | template <typename AtContainer, typename T, T... I> |
| 22 | auto ( const AtContainer &t, const std::integer_sequence<T, I...> ) |
| 23 | -> decltype ( std::make_tuple ( std::get<I>(t)... )) |
| 24 | { return std::make_tuple ( std::get<I>(t)... ); } |
| 25 | |
| 26 | int main(int, char**) |
| 27 | { |
| 28 | // Make a couple of sequences |
| 29 | using int3 = std::make_integer_sequence<int, 3>; // generates int: 0,1,2 |
| 30 | using size7 = std::make_integer_sequence<std::size_t, 7>; // generates size_t: 0,1,2,3,4,5,6 |
| 31 | using size4 = std::make_index_sequence<4>; // generates size_t: 0,1,2,3 |
| 32 | using size2 = std::index_sequence_for<int, std::size_t>; // generates size_t: 0,1 |
| 33 | using intmix = std::integer_sequence<int, 9, 8, 7, 2>; // generates int: 9,8,7,2 |
| 34 | using sizemix = std::index_sequence<1, 1, 2, 3, 5>; // generates size_t: 1,1,2,3,5 |
| 35 | |
| 36 | // Make sure they're what we expect |
| 37 | static_assert ( std::is_same<int3::value_type, int>::value, "int3 type wrong" ); |
| 38 | static_assert ( int3::size () == 3, "int3 size wrong" ); |
| 39 | |
| 40 | static_assert ( std::is_same<size7::value_type, std::size_t>::value, "size7 type wrong" ); |
| 41 | static_assert ( size7::size () == 7, "size7 size wrong" ); |
| 42 | |
| 43 | static_assert ( std::is_same<size4::value_type, std::size_t>::value, "size4 type wrong" ); |
| 44 | static_assert ( size4::size () == 4, "size4 size wrong" ); |
| 45 | |
| 46 | static_assert ( std::is_same<size2::value_type, std::size_t>::value, "size2 type wrong" ); |
| 47 | static_assert ( size2::size () == 2, "size2 size wrong" ); |
| 48 | |
| 49 | static_assert ( std::is_same<intmix::value_type, int>::value, "intmix type wrong" ); |
| 50 | static_assert ( intmix::size () == 4, "intmix size wrong" ); |
| 51 | |
| 52 | static_assert ( std::is_same<sizemix::value_type, std::size_t>::value, "sizemix type wrong" ); |
| 53 | static_assert ( sizemix::size () == 5, "sizemix size wrong" ); |
| 54 | |
| 55 | auto tup = std::make_tuple ( args: 10, args: 11, args: 12, args: 13, args: 14, args: 15, args: 16, args: 17, args: 18, args: 19, args: 20 ); |
| 56 | |
| 57 | // Use them |
| 58 | auto t3 = extract ( tup, int3() ); |
| 59 | static_assert ( std::tuple_size<decltype(t3)>::value == int3::size (), "t3 size wrong" ); |
| 60 | assert ( t3 == std::make_tuple ( 10, 11, 12 )); |
| 61 | |
| 62 | auto t7 = extract ( tup, size7 ()); |
| 63 | static_assert ( std::tuple_size<decltype(t7)>::value == size7::size (), "t7 size wrong" ); |
| 64 | assert ( t7 == std::make_tuple ( 10, 11, 12, 13, 14, 15, 16 )); |
| 65 | |
| 66 | auto t4 = extract ( tup, size4 ()); |
| 67 | static_assert ( std::tuple_size<decltype(t4)>::value == size4::size (), "t4 size wrong" ); |
| 68 | assert ( t4 == std::make_tuple ( 10, 11, 12, 13 )); |
| 69 | |
| 70 | auto t2 = extract ( tup, size2 ()); |
| 71 | static_assert ( std::tuple_size<decltype(t2)>::value == size2::size (), "t2 size wrong" ); |
| 72 | assert ( t2 == std::make_tuple ( 10, 11 )); |
| 73 | |
| 74 | auto tintmix = extract ( tup, intmix ()); |
| 75 | static_assert ( std::tuple_size<decltype(tintmix)>::value == intmix::size (), "tintmix size wrong" ); |
| 76 | assert ( tintmix == std::make_tuple ( 19, 18, 17, 12 )); |
| 77 | |
| 78 | auto tsizemix = extract ( tup, sizemix ()); |
| 79 | static_assert ( std::tuple_size<decltype(tsizemix)>::value == sizemix::size (), "tsizemix size wrong" ); |
| 80 | assert ( tsizemix == std::make_tuple ( 11, 11, 12, 13, 15 )); |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |