xref: /freebsd/contrib/llvm-project/libcxx/include/__tuple/tuple_element.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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_TUPLE_ELEMENT_H
10 #define _LIBCPP___TUPLE_TUPLE_ELEMENT_H
11 
12 #include <__config>
13 #include <__tuple/tuple_indices.h>
14 #include <__tuple/tuple_types.h>
15 #include <cstddef>
16 
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 #  pragma GCC system_header
19 #endif
20 
21 _LIBCPP_BEGIN_NAMESPACE_STD
22 
23 template <size_t _Ip, class _Tp>
24 struct _LIBCPP_TEMPLATE_VIS tuple_element;
25 
26 template <size_t _Ip, class _Tp>
27 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp> {
28   typedef _LIBCPP_NODEBUG const typename tuple_element<_Ip, _Tp>::type type;
29 };
30 
31 template <size_t _Ip, class _Tp>
32 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp> {
33   typedef _LIBCPP_NODEBUG volatile typename tuple_element<_Ip, _Tp>::type type;
34 };
35 
36 template <size_t _Ip, class _Tp>
37 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp> {
38   typedef _LIBCPP_NODEBUG const volatile typename tuple_element<_Ip, _Tp>::type type;
39 };
40 
41 #ifndef _LIBCPP_CXX03_LANG
42 
43 #  if !__has_builtin(__type_pack_element)
44 
45 namespace __indexer_detail {
46 
47 template <size_t _Idx, class _Tp>
48 struct __indexed {
49   using type _LIBCPP_NODEBUG = _Tp;
50 };
51 
52 template <class _Types, class _Indexes>
53 struct __indexer;
54 
55 template <class... _Types, size_t... _Idx>
56 struct __indexer<__tuple_types<_Types...>, __tuple_indices<_Idx...>> : __indexed<_Idx, _Types>... {};
57 
58 template <size_t _Idx, class _Tp>
59 __indexed<_Idx, _Tp> __at_index(__indexed<_Idx, _Tp> const&);
60 
61 } // namespace __indexer_detail
62 
63 template <size_t _Idx, class... _Types>
64 using __type_pack_element _LIBCPP_NODEBUG = typename decltype(__indexer_detail::__at_index<_Idx>(
65     __indexer_detail::__indexer< __tuple_types<_Types...>,
66                                  typename __make_tuple_indices<sizeof...(_Types)>::type >{}))::type;
67 #  endif
68 
69 template <size_t _Ip, class... _Types>
70 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...> > {
71   static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range");
72   typedef _LIBCPP_NODEBUG __type_pack_element<_Ip, _Types...> type;
73 };
74 
75 #  if _LIBCPP_STD_VER >= 14
76 template <size_t _Ip, class... _Tp>
77 using tuple_element_t _LIBCPP_NODEBUG = typename tuple_element<_Ip, _Tp...>::type;
78 #  endif
79 
80 #endif // _LIBCPP_CXX03_LANG
81 
82 _LIBCPP_END_NAMESPACE_STD
83 
84 #endif // _LIBCPP___TUPLE_TUPLE_ELEMENT_H
85