1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11
12 // class make_integer_sequence
16 #include <type_traits>
19 #include "test_macros.h"
21 template <typename AtContainer
, typename T
, T
... I
>
22 auto extract ( 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
)... ); }
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
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" );
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" );
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" );
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" );
49 static_assert ( std::is_same
<intmix::value_type
, int>::value
, "intmix type wrong" );
50 static_assert ( intmix::size () == 4, "intmix size wrong" );
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" );
55 auto tup
= std::make_tuple ( 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 );
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 ));
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 ));
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 ));
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 ));
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 ));
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 ));