tuple 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // -*- C++ -*-
  2. //===----------------------------- tuple ----------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_EXPERIMENTAL_TUPLE
  11. #define _LIBCPP_EXPERIMENTAL_TUPLE
  12. /*
  13. experimental/tuple synopsis
  14. // C++1y
  15. #include <tuple>
  16. namespace std {
  17. namespace experimental {
  18. inline namespace fundamentals_v1 {
  19. // See C++14 20.4.2.5, tuple helper classes
  20. template <class T> constexpr size_t tuple_size_v
  21. = tuple_size<T>::value;
  22. // 3.2.2, Calling a function with a tuple of arguments
  23. template <class F, class Tuple>
  24. constexpr decltype(auto) apply(F&& f, Tuple&& t);
  25. } // namespace fundamentals_v1
  26. } // namespace experimental
  27. } // namespace std
  28. */
  29. # include <experimental/__config>
  30. #if _LIBCPP_STD_VER > 11
  31. # include <tuple>
  32. # include <utility>
  33. # include <__functional_base>
  34. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  35. #pragma GCC system_header
  36. #endif
  37. _LIBCPP_BEGIN_NAMESPACE_LFTS
  38. #ifndef _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
  39. template <class _Tp>
  40. _LIBCPP_CONSTEXPR size_t tuple_size_v = tuple_size<_Tp>::value;
  41. #endif
  42. template <class _Fn, class _Tuple, size_t ..._Id>
  43. inline _LIBCPP_INLINE_VISIBILITY
  44. _LIBCPP_CONSTEXPR_AFTER_CXX11
  45. decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
  46. integer_sequence<size_t, _Id...>) {
  47. return _VSTD::__invoke_constexpr(
  48. _VSTD::forward<_Fn>(__f),
  49. _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...
  50. );
  51. }
  52. template <class _Fn, class _Tuple>
  53. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
  54. decltype(auto) apply(_Fn && __f, _Tuple && __t) {
  55. return _VSTD_LFTS::__apply_tuple_impl(
  56. _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
  57. make_index_sequence<tuple_size<typename decay<_Tuple>::type>::value>()
  58. );
  59. }
  60. _LIBCPP_END_NAMESPACE_LFTS
  61. #endif /* _LIBCPP_STD_VER > 11 */
  62. #endif /* _LIBCPP_EXPERIMENTAL_TUPLE */