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 #ifndef _LIBCPP___TUPLE_MAKE_TUPLE_TYPES_H
10 #define _LIBCPP___TUPLE_MAKE_TUPLE_TYPES_H
11 
12 #include <__config>
13 #include <__fwd/array.h>
14 #include <__fwd/tuple.h>
15 #include <__tuple/tuple_element.h>
16 #include <__tuple/tuple_indices.h>
17 #include <__tuple/tuple_size.h>
18 #include <__tuple/tuple_types.h>
19 #include <__type_traits/apply_cv.h>
20 #include <__type_traits/remove_cv.h>
21 #include <__type_traits/remove_reference.h>
22 #include <cstddef>
23 
24 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25 #  pragma GCC system_header
26 #endif
27 
28 #ifndef _LIBCPP_CXX03_LANG
29 
30 _LIBCPP_BEGIN_NAMESPACE_STD
31 
32 // __make_tuple_types<_Tuple<_Types...>, _Ep, _Sp>::type is a
33 // __tuple_types<_Types...> using only those _Types in the range [_Sp, _Ep).
34 // _Sp defaults to 0 and _Ep defaults to tuple_size<_Tuple>.  If _Tuple is a
35 // lvalue_reference type, then __tuple_types<_Types&...> is the result.
36 
37 template <class _TupleTypes, class _TupleIndices>
38 struct __make_tuple_types_flat;
39 
40 template <template <class...> class _Tuple, class... _Types, size_t... _Idx>
41 struct __make_tuple_types_flat<_Tuple<_Types...>, __tuple_indices<_Idx...>> {
42   // Specialization for pair, tuple, and __tuple_types
43   template <class _Tp>
44   using __apply_quals _LIBCPP_NODEBUG = __tuple_types<__apply_cv_t<_Tp, __type_pack_element<_Idx, _Types...>>...>;
45 };
46 
47 template <class _Vt, size_t _Np, size_t... _Idx>
48 struct __make_tuple_types_flat<array<_Vt, _Np>, __tuple_indices<_Idx...>> {
49   template <size_t>
50   using __value_type = _Vt;
51   template <class _Tp>
52   using __apply_quals = __tuple_types<__apply_cv_t<_Tp, __value_type<_Idx>>...>;
53 };
54 
55 template <class _Tp,
56           size_t _Ep     = tuple_size<__libcpp_remove_reference_t<_Tp> >::value,
57           size_t _Sp     = 0,
58           bool _SameSize = (_Ep == tuple_size<__libcpp_remove_reference_t<_Tp> >::value)>
59 struct __make_tuple_types {
60   static_assert(_Sp <= _Ep, "__make_tuple_types input error");
61   using _RawTp = __remove_cv_t<__libcpp_remove_reference_t<_Tp> >;
62   using _Maker = __make_tuple_types_flat<_RawTp, typename __make_tuple_indices<_Ep, _Sp>::type>;
63   using type   = typename _Maker::template __apply_quals<_Tp>;
64 };
65 
66 template <class... _Types, size_t _Ep>
67 struct __make_tuple_types<tuple<_Types...>, _Ep, 0, true> {
68   typedef _LIBCPP_NODEBUG __tuple_types<_Types...> type;
69 };
70 
71 template <class... _Types, size_t _Ep>
72 struct __make_tuple_types<__tuple_types<_Types...>, _Ep, 0, true> {
73   typedef _LIBCPP_NODEBUG __tuple_types<_Types...> type;
74 };
75 
76 _LIBCPP_END_NAMESPACE_STD
77 
78 #endif // _LIBCPP_CXX03_LANG
79 
80 #endif // _LIBCPP___TUPLE_MAKE_TUPLE_TYPES_H
81