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