![Eric Fiselier](/assets/img/avatar_default.png)
Summary: This patch adds the `<experimental/tuple>` header (almost) as specified in the latest draft of the library fundamentals TS. The main changes in this patch are: 1. Added variable template `tuple_size_v` 2. Added function `apply(Func &&, Tuple &&)`. 3. Changed `__invoke` to be `_LIBCPP_CONSTEXPR_AFTER_CXX11`. The `apply(...)` implementation uses `__invoke` to invoke the given function. `__invoke` already provides the required functionality. Using `__invoke` also allows `apply` to be used on pointers to member function/objects as an extension. In order to facilitate this `__invoke` has to be marked `constexpr`. Test Plan: Each new feature was tested. The test cases for `tuple_size_v` are as follows: 1. tuple_size_v.pass.cpp - Check `tuple_size_v` on cv qualified tuples, pairs and arrays. 2. tuple_size_v.fail.cpp - Test on reference type. 3. tuple_size_v_2.fail.cpp - Test on non-tuple 4. tuple_size_v_3.fail.cpp - Test on pointer type. The test cases for tuple.apply are as follows: 1. arg_type.pass.cpp - Ensure that ref/pointer/cv qualified types are properly passed. 2. constexpr_types.pass.cpp - Ensure constexpr evaluation of apply is possible for `tuple` and `pair`. 3. extended_types.pass.cpp - Test apply on function types permitted by extension. 4. large_arity.pass.cpp - Test that apply can evaluated on tuples and arrays with large sizes. 5. ref_qualifiers.pass.cpp - Test that apply respects ref qualified functions. 6. return_type.pass.cpp - Test that apply returns the proper type. 7. types.pass.cpp - Test apply on function types as required by LFTS. Reviewers: mclow.lists Reviewed By: mclow.lists Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4512 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@232515 91177308-0d34-0410-b5e6-96231b3b80d8
82 lines
2.1 KiB
C++
82 lines
2.1 KiB
C++
// -*- C++ -*-
|
|
//===----------------------------- tuple ----------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
// Source Licenses. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef _LIBCPP_EXPERIMENTAL_TUPLE
|
|
#define _LIBCPP_EXPERIMENTAL_TUPLE
|
|
|
|
/*
|
|
experimental/tuple synopsis
|
|
|
|
// C++1y
|
|
|
|
#include <tuple>
|
|
|
|
namespace std {
|
|
namespace experimental {
|
|
inline namespace fundamentals_v1 {
|
|
|
|
// See C++14 20.4.2.5, tuple helper classes
|
|
template <class T> constexpr size_t tuple_size_v
|
|
= tuple_size<T>::value;
|
|
|
|
// 3.2.2, Calling a function with a tuple of arguments
|
|
template <class F, class Tuple>
|
|
constexpr decltype(auto) apply(F&& f, Tuple&& t);
|
|
|
|
} // namespace fundamentals_v1
|
|
} // namespace experimental
|
|
} // namespace std
|
|
|
|
*/
|
|
|
|
# include <experimental/__config>
|
|
|
|
#if _LIBCPP_STD_VER > 11
|
|
|
|
# include <tuple>
|
|
# include <utility>
|
|
# include <__functional_base>
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
|
#pragma GCC system_header
|
|
#endif
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_LFTS
|
|
|
|
#ifndef _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
|
|
template <class _Tp>
|
|
_LIBCPP_CONSTEXPR size_t tuple_size_v = tuple_size<_Tp>::value;
|
|
#endif
|
|
|
|
template <class _Fn, class _Tuple, size_t ..._Id>
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
|
|
integer_sequence<size_t, _Id...>) {
|
|
return _VSTD::__invoke(
|
|
_VSTD::forward<_Fn>(__f),
|
|
_VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...
|
|
);
|
|
}
|
|
|
|
template <class _Fn, class _Tuple>
|
|
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
|
|
decltype(auto) apply(_Fn && __f, _Tuple && __t) {
|
|
return _VSTD_LFTS::__apply_tuple_impl(
|
|
_VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
|
|
make_index_sequence<tuple_size<typename decay<_Tuple>::type>::value>()
|
|
);
|
|
}
|
|
|
|
_LIBCPP_END_NAMESPACE_LFTS
|
|
|
|
#endif /* _LIBCPP_STD_VER > 11 */
|
|
|
|
#endif /* _LIBCPP_EXPERIMENTAL_TUPLE */
|