Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __tuple / tuple_element.h
blob478dd089d46c66ccc69fa56d6cacdec9c27b90ab
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 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___TUPLE_TUPLE_ELEMENT_H
10 #define _LIBCPP___TUPLE_TUPLE_ELEMENT_H
12 #include <__config>
13 #include <__tuple/tuple_indices.h>
14 #include <__tuple/tuple_types.h>
15 #include <__type_traits/add_const.h>
16 #include <__type_traits/add_cv.h>
17 #include <__type_traits/add_volatile.h>
18 #include <cstddef>
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 # pragma GCC system_header
22 #endif
24 _LIBCPP_BEGIN_NAMESPACE_STD
26 template <size_t _Ip, class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_element;
28 template <size_t _Ip, class _Tp>
29 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp>
31 typedef _LIBCPP_NODEBUG typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type;
34 template <size_t _Ip, class _Tp>
35 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp>
37 typedef _LIBCPP_NODEBUG typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type;
40 template <size_t _Ip, class _Tp>
41 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp>
43 typedef _LIBCPP_NODEBUG typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type;
46 #ifndef _LIBCPP_CXX03_LANG
48 #if !__has_builtin(__type_pack_element)
50 namespace __indexer_detail {
52 template <size_t _Idx, class _Tp>
53 struct __indexed { using type _LIBCPP_NODEBUG = _Tp; };
55 template <class _Types, class _Indexes> struct __indexer;
57 template <class ..._Types, size_t ..._Idx>
58 struct __indexer<__tuple_types<_Types...>, __tuple_indices<_Idx...>>
59 : __indexed<_Idx, _Types>...
60 {};
62 template <size_t _Idx, class _Tp>
63 __indexed<_Idx, _Tp> __at_index(__indexed<_Idx, _Tp> const&);
65 } // namespace __indexer_detail
67 template <size_t _Idx, class ..._Types>
68 using __type_pack_element _LIBCPP_NODEBUG = typename decltype(
69 __indexer_detail::__at_index<_Idx>(
70 __indexer_detail::__indexer<
71 __tuple_types<_Types...>,
72 typename __make_tuple_indices<sizeof...(_Types)>::type
73 >{})
74 )::type;
75 #endif
77 template <size_t _Ip, class ..._Types>
78 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...> >
80 static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range");
81 typedef _LIBCPP_NODEBUG __type_pack_element<_Ip, _Types...> type;
84 #if _LIBCPP_STD_VER >= 14
85 template <size_t _Ip, class ..._Tp>
86 using tuple_element_t _LIBCPP_NODEBUG = typename tuple_element <_Ip, _Tp...>::type;
87 #endif
89 #endif // _LIBCPP_CXX03_LANG
91 _LIBCPP_END_NAMESPACE_STD
93 #endif // _LIBCPP___TUPLE_TUPLE_ELEMENT_H