__tuple revision 261272
1227825Stheraven// -*- C++ -*- 2227825Stheraven//===----------------------------------------------------------------------===// 3227825Stheraven// 4227825Stheraven// The LLVM Compiler Infrastructure 5227825Stheraven// 6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open 7227825Stheraven// Source Licenses. See LICENSE.TXT for details. 8227825Stheraven// 9227825Stheraven//===----------------------------------------------------------------------===// 10227825Stheraven 11227825Stheraven#ifndef _LIBCPP___TUPLE 12227825Stheraven#define _LIBCPP___TUPLE 13227825Stheraven 14227825Stheraven#include <__config> 15227825Stheraven#include <cstddef> 16227825Stheraven#include <type_traits> 17227825Stheraven 18227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 19227825Stheraven#pragma GCC system_header 20227825Stheraven#endif 21227825Stheraven 22227825Stheraven#ifdef _LIBCPP_HAS_NO_VARIADICS 23227825Stheraven 24227825Stheraven#include <__tuple_03> 25227825Stheraven 26227825Stheraven#else // _LIBCPP_HAS_NO_VARIADICS 27227825Stheraven 28227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD 29227825Stheraven 30261272Sdimtemplate <class _Tp> class _LIBCPP_TYPE_VIS_ONLY tuple_size; 31227825Stheraven 32227825Stheraventemplate <class _Tp> 33261272Sdimclass _LIBCPP_TYPE_VIS_ONLY tuple_size<const _Tp> 34227825Stheraven : public tuple_size<_Tp> {}; 35227825Stheraven 36227825Stheraventemplate <class _Tp> 37261272Sdimclass _LIBCPP_TYPE_VIS_ONLY tuple_size<volatile _Tp> 38227825Stheraven : public tuple_size<_Tp> {}; 39227825Stheraven 40227825Stheraventemplate <class _Tp> 41261272Sdimclass _LIBCPP_TYPE_VIS_ONLY tuple_size<const volatile _Tp> 42227825Stheraven : public tuple_size<_Tp> {}; 43227825Stheraven 44261272Sdimtemplate <size_t _Ip, class _Tp> class _LIBCPP_TYPE_VIS_ONLY tuple_element; 45227825Stheraven 46227825Stheraventemplate <size_t _Ip, class _Tp> 47261272Sdimclass _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, const _Tp> 48227825Stheraven{ 49227825Stheravenpublic: 50227825Stheraven typedef typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type; 51227825Stheraven}; 52227825Stheraven 53227825Stheraventemplate <size_t _Ip, class _Tp> 54261272Sdimclass _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, volatile _Tp> 55227825Stheraven{ 56227825Stheravenpublic: 57227825Stheraven typedef typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type; 58227825Stheraven}; 59227825Stheraven 60227825Stheraventemplate <size_t _Ip, class _Tp> 61261272Sdimclass _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, const volatile _Tp> 62227825Stheraven{ 63227825Stheravenpublic: 64227825Stheraven typedef typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type; 65227825Stheraven}; 66227825Stheraven 67261272Sdimtemplate <class ..._Tp> class _LIBCPP_TYPE_VIS_ONLY tuple; 68261272Sdimtemplate <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY pair; 69261272Sdimtemplate <class _Tp, size_t _Size> struct _LIBCPP_TYPE_VIS_ONLY array; 70227825Stheraven 71227825Stheraventemplate <class _Tp> struct __tuple_like : false_type {}; 72227825Stheraven 73227825Stheraventemplate <class _Tp> struct __tuple_like<const _Tp> : public __tuple_like<_Tp> {}; 74227825Stheraventemplate <class _Tp> struct __tuple_like<volatile _Tp> : public __tuple_like<_Tp> {}; 75227825Stheraventemplate <class _Tp> struct __tuple_like<const volatile _Tp> : public __tuple_like<_Tp> {}; 76227825Stheraven 77227825Stheraventemplate <class... _Tp> struct __tuple_like<tuple<_Tp...> > : true_type {}; 78227825Stheraventemplate <class _T1, class _T2> struct __tuple_like<pair<_T1, _T2> > : true_type {}; 79227825Stheraventemplate <class _Tp, size_t _Size> struct __tuple_like<array<_Tp, _Size> > : true_type {}; 80227825Stheraven 81227825Stheraventemplate <size_t _Ip, class ..._Tp> 82261272Sdim_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 83227825Stheraventypename tuple_element<_Ip, tuple<_Tp...> >::type& 84227825Stheravenget(tuple<_Tp...>&) _NOEXCEPT; 85227825Stheraven 86227825Stheraventemplate <size_t _Ip, class ..._Tp> 87261272Sdim_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 88227825Stheravenconst typename tuple_element<_Ip, tuple<_Tp...> >::type& 89227825Stheravenget(const tuple<_Tp...>&) _NOEXCEPT; 90227825Stheraven 91227825Stheraventemplate <size_t _Ip, class ..._Tp> 92261272Sdim_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 93227825Stheraventypename tuple_element<_Ip, tuple<_Tp...> >::type&& 94227825Stheravenget(tuple<_Tp...>&&) _NOEXCEPT; 95227825Stheraven 96227825Stheraventemplate <size_t _Ip, class _T1, class _T2> 97261272Sdim_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 98227825Stheraventypename tuple_element<_Ip, pair<_T1, _T2> >::type& 99227825Stheravenget(pair<_T1, _T2>&) _NOEXCEPT; 100227825Stheraven 101227825Stheraventemplate <size_t _Ip, class _T1, class _T2> 102261272Sdim_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 103227825Stheravenconst typename tuple_element<_Ip, pair<_T1, _T2> >::type& 104227825Stheravenget(const pair<_T1, _T2>&) _NOEXCEPT; 105227825Stheraven 106227825Stheraventemplate <size_t _Ip, class _T1, class _T2> 107261272Sdim_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 108227825Stheraventypename tuple_element<_Ip, pair<_T1, _T2> >::type&& 109227825Stheravenget(pair<_T1, _T2>&&) _NOEXCEPT; 110227825Stheraven 111227825Stheraventemplate <size_t _Ip, class _Tp, size_t _Size> 112261272Sdim_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 113227825Stheraven_Tp& 114227825Stheravenget(array<_Tp, _Size>&) _NOEXCEPT; 115227825Stheraven 116227825Stheraventemplate <size_t _Ip, class _Tp, size_t _Size> 117261272Sdim_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 118227825Stheravenconst _Tp& 119227825Stheravenget(const array<_Tp, _Size>&) _NOEXCEPT; 120227825Stheraven 121227825Stheraventemplate <size_t _Ip, class _Tp, size_t _Size> 122261272Sdim_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 123227825Stheraven_Tp&& 124227825Stheravenget(array<_Tp, _Size>&&) _NOEXCEPT; 125227825Stheraven 126227825Stheraven// __make_tuple_indices 127227825Stheraven 128227825Stheraventemplate <size_t...> struct __tuple_indices {}; 129227825Stheraven 130227825Stheraventemplate <size_t _Sp, class _IntTuple, size_t _Ep> 131227825Stheravenstruct __make_indices_imp; 132227825Stheraven 133227825Stheraventemplate <size_t _Sp, size_t ..._Indices, size_t _Ep> 134227825Stheravenstruct __make_indices_imp<_Sp, __tuple_indices<_Indices...>, _Ep> 135227825Stheraven{ 136227825Stheraven typedef typename __make_indices_imp<_Sp+1, __tuple_indices<_Indices..., _Sp>, _Ep>::type type; 137227825Stheraven}; 138227825Stheraven 139227825Stheraventemplate <size_t _Ep, size_t ..._Indices> 140227825Stheravenstruct __make_indices_imp<_Ep, __tuple_indices<_Indices...>, _Ep> 141227825Stheraven{ 142227825Stheraven typedef __tuple_indices<_Indices...> type; 143227825Stheraven}; 144227825Stheraven 145227825Stheraventemplate <size_t _Ep, size_t _Sp = 0> 146227825Stheravenstruct __make_tuple_indices 147227825Stheraven{ 148227825Stheraven static_assert(_Sp <= _Ep, "__make_tuple_indices input error"); 149227825Stheraven typedef typename __make_indices_imp<_Sp, __tuple_indices<>, _Ep>::type type; 150227825Stheraven}; 151227825Stheraven 152227825Stheraven// __tuple_types 153227825Stheraven 154227825Stheraventemplate <class ..._Tp> struct __tuple_types {}; 155227825Stheraven 156227825Stheraventemplate <size_t _Ip> 157261272Sdimclass _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, __tuple_types<> > 158227825Stheraven{ 159227825Stheravenpublic: 160227825Stheraven static_assert(_Ip == 0, "tuple_element index out of range"); 161227825Stheraven static_assert(_Ip != 0, "tuple_element index out of range"); 162227825Stheraven}; 163227825Stheraven 164227825Stheraventemplate <class _Hp, class ..._Tp> 165261272Sdimclass _LIBCPP_TYPE_VIS_ONLY tuple_element<0, __tuple_types<_Hp, _Tp...> > 166227825Stheraven{ 167227825Stheravenpublic: 168227825Stheraven typedef _Hp type; 169227825Stheraven}; 170227825Stheraven 171227825Stheraventemplate <size_t _Ip, class _Hp, class ..._Tp> 172261272Sdimclass _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, __tuple_types<_Hp, _Tp...> > 173227825Stheraven{ 174227825Stheravenpublic: 175227825Stheraven typedef typename tuple_element<_Ip-1, __tuple_types<_Tp...> >::type type; 176227825Stheraven}; 177227825Stheraven 178227825Stheraventemplate <class ..._Tp> 179261272Sdimclass _LIBCPP_TYPE_VIS_ONLY tuple_size<__tuple_types<_Tp...> > 180227825Stheraven : public integral_constant<size_t, sizeof...(_Tp)> 181227825Stheraven{ 182227825Stheraven}; 183227825Stheraven 184227825Stheraventemplate <class... _Tp> struct __tuple_like<__tuple_types<_Tp...> > : true_type {}; 185227825Stheraven 186227825Stheraven// __make_tuple_types 187227825Stheraven 188227825Stheraven// __make_tuple_types<_Tuple<_Types...>, _Ep, _Sp>::type is a 189227825Stheraven// __tuple_types<_Types...> using only those _Types in the range [_Sp, _Ep). 190227825Stheraven// _Sp defaults to 0 and _Ep defaults to tuple_size<_Tuple>. If _Tuple is a 191227825Stheraven// lvalue_reference type, then __tuple_types<_Types&...> is the result. 192227825Stheraven 193227825Stheraventemplate <class _TupleTypes, class _Tp, size_t _Sp, size_t _Ep> 194227825Stheravenstruct __make_tuple_types_imp; 195227825Stheraven 196227825Stheraventemplate <class ..._Types, class _Tp, size_t _Sp, size_t _Ep> 197227825Stheravenstruct __make_tuple_types_imp<__tuple_types<_Types...>, _Tp, _Sp, _Ep> 198227825Stheraven{ 199227825Stheraven typedef typename remove_reference<_Tp>::type _Tpr; 200227825Stheraven typedef typename __make_tuple_types_imp<__tuple_types<_Types..., 201227825Stheraven typename conditional<is_lvalue_reference<_Tp>::value, 202227825Stheraven typename tuple_element<_Sp, _Tpr>::type&, 203227825Stheraven typename tuple_element<_Sp, _Tpr>::type>::type>, 204227825Stheraven _Tp, _Sp+1, _Ep>::type type; 205227825Stheraven}; 206227825Stheraven 207227825Stheraventemplate <class ..._Types, class _Tp, size_t _Ep> 208227825Stheravenstruct __make_tuple_types_imp<__tuple_types<_Types...>, _Tp, _Ep, _Ep> 209227825Stheraven{ 210227825Stheraven typedef __tuple_types<_Types...> type; 211227825Stheraven}; 212227825Stheraven 213227825Stheraventemplate <class _Tp, size_t _Ep = tuple_size<typename remove_reference<_Tp>::type>::value, size_t _Sp = 0> 214227825Stheravenstruct __make_tuple_types 215227825Stheraven{ 216227825Stheraven static_assert(_Sp <= _Ep, "__make_tuple_types input error"); 217227825Stheraven typedef typename __make_tuple_types_imp<__tuple_types<>, _Tp, _Sp, _Ep>::type type; 218227825Stheraven}; 219227825Stheraven 220227825Stheraven// __tuple_convertible 221227825Stheraven 222227825Stheraventemplate <bool, class _Tp, class _Up> 223227825Stheravenstruct __tuple_convertible_imp : public false_type {}; 224227825Stheraven 225227825Stheraventemplate <class _Tp0, class ..._Tp, class _Up0, class ..._Up> 226227825Stheravenstruct __tuple_convertible_imp<true, __tuple_types<_Tp0, _Tp...>, __tuple_types<_Up0, _Up...> > 227227825Stheraven : public integral_constant<bool, 228234959Stheraven is_convertible<_Tp0, _Up0>::value && 229227825Stheraven __tuple_convertible_imp<true, __tuple_types<_Tp...>, __tuple_types<_Up...> >::value> {}; 230227825Stheraven 231227825Stheraventemplate <> 232227825Stheravenstruct __tuple_convertible_imp<true, __tuple_types<>, __tuple_types<> > 233227825Stheraven : public true_type {}; 234227825Stheraven 235227825Stheraventemplate <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value, 236227825Stheraven bool = __tuple_like<_Up>::value> 237227825Stheravenstruct __tuple_convertible 238227825Stheraven : public false_type {}; 239227825Stheraven 240227825Stheraventemplate <class _Tp, class _Up> 241227825Stheravenstruct __tuple_convertible<_Tp, _Up, true, true> 242227825Stheraven : public __tuple_convertible_imp<tuple_size<typename remove_reference<_Tp>::type>::value == 243227825Stheraven tuple_size<_Up>::value, 244227825Stheraven typename __make_tuple_types<_Tp>::type, typename __make_tuple_types<_Up>::type> 245227825Stheraven{}; 246227825Stheraven 247234959Stheraven// __tuple_constructible 248234959Stheraven 249234959Stheraventemplate <bool, class _Tp, class _Up> 250234959Stheravenstruct __tuple_constructible_imp : public false_type {}; 251234959Stheraven 252234959Stheraventemplate <class _Tp0, class ..._Tp, class _Up0, class ..._Up> 253234959Stheravenstruct __tuple_constructible_imp<true, __tuple_types<_Tp0, _Tp...>, __tuple_types<_Up0, _Up...> > 254234959Stheraven : public integral_constant<bool, 255234959Stheraven is_constructible<_Up0, _Tp0>::value && 256234959Stheraven __tuple_constructible_imp<true, __tuple_types<_Tp...>, __tuple_types<_Up...> >::value> {}; 257234959Stheraven 258234959Stheraventemplate <> 259234959Stheravenstruct __tuple_constructible_imp<true, __tuple_types<>, __tuple_types<> > 260234959Stheraven : public true_type {}; 261234959Stheraven 262234959Stheraventemplate <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value, 263234959Stheraven bool = __tuple_like<_Up>::value> 264234959Stheravenstruct __tuple_constructible 265234959Stheraven : public false_type {}; 266234959Stheraven 267234959Stheraventemplate <class _Tp, class _Up> 268234959Stheravenstruct __tuple_constructible<_Tp, _Up, true, true> 269234959Stheraven : public __tuple_constructible_imp<tuple_size<typename remove_reference<_Tp>::type>::value == 270234959Stheraven tuple_size<_Up>::value, 271234959Stheraven typename __make_tuple_types<_Tp>::type, typename __make_tuple_types<_Up>::type> 272234959Stheraven{}; 273234959Stheraven 274227825Stheraven// __tuple_assignable 275227825Stheraven 276227825Stheraventemplate <bool, class _Tp, class _Up> 277227825Stheravenstruct __tuple_assignable_imp : public false_type {}; 278227825Stheraven 279227825Stheraventemplate <class _Tp0, class ..._Tp, class _Up0, class ..._Up> 280227825Stheravenstruct __tuple_assignable_imp<true, __tuple_types<_Tp0, _Tp...>, __tuple_types<_Up0, _Up...> > 281227825Stheraven : public integral_constant<bool, 282227825Stheraven is_assignable<_Up0&, _Tp0>::value && 283227825Stheraven __tuple_assignable_imp<true, __tuple_types<_Tp...>, __tuple_types<_Up...> >::value> {}; 284227825Stheraven 285227825Stheraventemplate <> 286227825Stheravenstruct __tuple_assignable_imp<true, __tuple_types<>, __tuple_types<> > 287227825Stheraven : public true_type {}; 288227825Stheraven 289227825Stheraventemplate <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value, 290227825Stheraven bool = __tuple_like<_Up>::value> 291227825Stheravenstruct __tuple_assignable 292227825Stheraven : public false_type {}; 293227825Stheraven 294227825Stheraventemplate <class _Tp, class _Up> 295227825Stheravenstruct __tuple_assignable<_Tp, _Up, true, true> 296227825Stheraven : public __tuple_assignable_imp<tuple_size<typename remove_reference<_Tp>::type>::value == 297227825Stheraven tuple_size<_Up>::value, 298227825Stheraven typename __make_tuple_types<_Tp>::type, typename __make_tuple_types<_Up>::type> 299227825Stheraven{}; 300227825Stheraven 301227825Stheraven_LIBCPP_END_NAMESPACE_STD 302227825Stheraven 303227825Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 304227825Stheraven 305227825Stheraven#endif // _LIBCPP___TUPLE 306