xref: /freebsd/contrib/llvm-project/libcxx/include/__tuple/tuple_element.h (revision 2f2ebe758bea201830bd021525424813f7fc6c6b)
106c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
206c3fb27SDimitry Andric //
306c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
406c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
506c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
606c3fb27SDimitry Andric //
706c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
806c3fb27SDimitry Andric 
906c3fb27SDimitry Andric #ifndef _LIBCPP___TUPLE_TUPLE_ELEMENT_H
1006c3fb27SDimitry Andric #define _LIBCPP___TUPLE_TUPLE_ELEMENT_H
1106c3fb27SDimitry Andric 
1206c3fb27SDimitry Andric #include <__config>
1306c3fb27SDimitry Andric #include <__tuple/tuple_indices.h>
1406c3fb27SDimitry Andric #include <__tuple/tuple_types.h>
1506c3fb27SDimitry Andric #include <cstddef>
1606c3fb27SDimitry Andric 
1706c3fb27SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1806c3fb27SDimitry Andric #  pragma GCC system_header
1906c3fb27SDimitry Andric #endif
2006c3fb27SDimitry Andric 
2106c3fb27SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
2206c3fb27SDimitry Andric 
23cb14a3feSDimitry Andric template <size_t _Ip, class _Tp>
24cb14a3feSDimitry Andric struct _LIBCPP_TEMPLATE_VIS tuple_element;
2506c3fb27SDimitry Andric 
2606c3fb27SDimitry Andric template <size_t _Ip, class _Tp>
27cb14a3feSDimitry Andric struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp> {
280fca6ea1SDimitry Andric   typedef _LIBCPP_NODEBUG const typename tuple_element<_Ip, _Tp>::type type;
2906c3fb27SDimitry Andric };
3006c3fb27SDimitry Andric 
3106c3fb27SDimitry Andric template <size_t _Ip, class _Tp>
32cb14a3feSDimitry Andric struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp> {
330fca6ea1SDimitry Andric   typedef _LIBCPP_NODEBUG volatile typename tuple_element<_Ip, _Tp>::type type;
3406c3fb27SDimitry Andric };
3506c3fb27SDimitry Andric 
3606c3fb27SDimitry Andric template <size_t _Ip, class _Tp>
37cb14a3feSDimitry Andric struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp> {
380fca6ea1SDimitry Andric   typedef _LIBCPP_NODEBUG const volatile typename tuple_element<_Ip, _Tp>::type type;
3906c3fb27SDimitry Andric };
4006c3fb27SDimitry Andric 
4106c3fb27SDimitry Andric #ifndef _LIBCPP_CXX03_LANG
4206c3fb27SDimitry Andric 
43*2f2ebe75SDimitry Andric #  if !__has_builtin(__type_pack_element)
44*2f2ebe75SDimitry Andric 
45*2f2ebe75SDimitry Andric namespace __indexer_detail {
46*2f2ebe75SDimitry Andric 
47*2f2ebe75SDimitry Andric template <size_t _Idx, class _Tp>
48*2f2ebe75SDimitry Andric struct __indexed {
49*2f2ebe75SDimitry Andric   using type _LIBCPP_NODEBUG = _Tp;
50*2f2ebe75SDimitry Andric };
51*2f2ebe75SDimitry Andric 
52*2f2ebe75SDimitry Andric template <class _Types, class _Indexes>
53*2f2ebe75SDimitry Andric struct __indexer;
54*2f2ebe75SDimitry Andric 
55*2f2ebe75SDimitry Andric template <class... _Types, size_t... _Idx>
56*2f2ebe75SDimitry Andric struct __indexer<__tuple_types<_Types...>, __tuple_indices<_Idx...>> : __indexed<_Idx, _Types>... {};
57*2f2ebe75SDimitry Andric 
58*2f2ebe75SDimitry Andric template <size_t _Idx, class _Tp>
59*2f2ebe75SDimitry Andric __indexed<_Idx, _Tp> __at_index(__indexed<_Idx, _Tp> const&);
60*2f2ebe75SDimitry Andric 
61*2f2ebe75SDimitry Andric } // namespace __indexer_detail
62*2f2ebe75SDimitry Andric 
63*2f2ebe75SDimitry Andric template <size_t _Idx, class... _Types>
64*2f2ebe75SDimitry Andric using __type_pack_element _LIBCPP_NODEBUG = typename decltype(__indexer_detail::__at_index<_Idx>(
65*2f2ebe75SDimitry Andric     __indexer_detail::__indexer< __tuple_types<_Types...>,
66*2f2ebe75SDimitry Andric                                  typename __make_tuple_indices<sizeof...(_Types)>::type >{}))::type;
67*2f2ebe75SDimitry Andric #  endif
68*2f2ebe75SDimitry Andric 
6906c3fb27SDimitry Andric template <size_t _Ip, class... _Types>
70cb14a3feSDimitry Andric struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...> > {
7106c3fb27SDimitry Andric   static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range");
7206c3fb27SDimitry Andric   typedef _LIBCPP_NODEBUG __type_pack_element<_Ip, _Types...> type;
7306c3fb27SDimitry Andric };
7406c3fb27SDimitry Andric 
7506c3fb27SDimitry Andric #  if _LIBCPP_STD_VER >= 14
7606c3fb27SDimitry Andric template <size_t _Ip, class... _Tp>
7706c3fb27SDimitry Andric using tuple_element_t _LIBCPP_NODEBUG = typename tuple_element<_Ip, _Tp...>::type;
7806c3fb27SDimitry Andric #  endif
7906c3fb27SDimitry Andric 
8006c3fb27SDimitry Andric #endif // _LIBCPP_CXX03_LANG
8106c3fb27SDimitry Andric 
8206c3fb27SDimitry Andric _LIBCPP_END_NAMESPACE_STD
8306c3fb27SDimitry Andric 
8406c3fb27SDimitry Andric #endif // _LIBCPP___TUPLE_TUPLE_ELEMENT_H
85