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> struct _LIBCPP_TEMPLATE_VIS tuple_element; 27 28 template <size_t _Ip, class _Tp> 29 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp> 30 { 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 { 37 typedef _LIBCPP_NODEBUG typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type; 38 }; 39 40 template <size_t _Ip, class _Tp> 41 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp> 42 { 43 typedef _LIBCPP_NODEBUG typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type; 44 }; 45 46 #ifndef _LIBCPP_CXX03_LANG 47 48 #if !__has_builtin(__type_pack_element) 49 50 namespace __indexer_detail { 51 52 template <size_t _Idx, class _Tp> 53 struct __indexed { using type _LIBCPP_NODEBUG = _Tp; }; 54 55 template <class _Types, class _Indexes> struct __indexer; 56 57 template <class ..._Types, size_t ..._Idx> 58 struct __indexer<__tuple_types<_Types...>, __tuple_indices<_Idx...>> 59 : __indexed<_Idx, _Types>... 60 {}; 61 62 template <size_t _Idx, class _Tp> 63 __indexed<_Idx, _Tp> __at_index(__indexed<_Idx, _Tp> const&); 64 65 } // namespace __indexer_detail 66 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 76 77 template <size_t _Ip, class ..._Types> 78 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...> > 79 { 80 static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range"); 81 typedef _LIBCPP_NODEBUG __type_pack_element<_Ip, _Types...> type; 82 }; 83 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 88 89 #endif // _LIBCPP_CXX03_LANG 90 91 _LIBCPP_END_NAMESPACE_STD 92 93 #endif // _LIBCPP___TUPLE_TUPLE_ELEMENT_H 94