From: Eric Fiselier Date: Mon, 18 Jul 2016 00:35:56 +0000 (+0000) Subject: Implement C++17 tuple bits. Including apply and make_from_tuple. X-Git-Tag: llvmorg-3.9.0-rc1~135 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=03e29a29646843081c403cf036578411502d1b8f;p=platform%2Fupstream%2Fllvm.git Implement C++17 tuple bits. Including apply and make_from_tuple. This patch upgrades to be C++17 compliant by implementing: * tuple_size_v: This was forgotten when implementing the other _v traits. * std::apply: This was added via LFTS v1 in p0220r1. * std::make_from_tuple: This was added in p0209r2. llvm-svn: 275745 --- diff --git a/libcxx/include/tuple b/libcxx/include/tuple index b0ab1c9..6805d8c 100644 --- a/libcxx/include/tuple +++ b/libcxx/include/tuple @@ -76,10 +76,18 @@ template tuple make_tuple(T&&...); // constexpr in C++14 template tuple forward_as_tuple(T&&...) noexcept; // constexpr in C++14 template tuple tie(T&...) noexcept; // constexpr in C++14 template tuple tuple_cat(Tuples&&... tpls); // constexpr in C++14 - + +// [tuple.apply], calling a function with a tuple of arguments: +template + constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17 +template + constexpr T make_from_tuple(Tuple&& t); // C++17 + // 20.4.1.4, tuple helper classes: template class tuple_size; // undefined template class tuple_size>; +template + constexpr size_t tuple_size_v = tuple_size::value; // C++17 template class tuple_element; // undefined template class tuple_element>; template @@ -1361,6 +1369,50 @@ pair<_T1, _T2>::pair(piecewise_construct_t, #endif // _LIBCPP_HAS_NO_VARIADICS +#if _LIBCPP_STD_VER > 14 +template +constexpr size_t tuple_size_v = tuple_size<_Tp>::value; + +#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; } + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t, + __tuple_indices<_Id...>) +_LIBCPP_NOEXCEPT_RETURN( + _VSTD::__invoke_constexpr( + _VSTD::forward<_Fn>(__f), + _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...) +) + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t) +_LIBCPP_NOEXCEPT_RETURN( + _VSTD::__apply_tuple_impl( + _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t), + typename __make_tuple_indices>>::type{}) +) + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>) +_LIBCPP_NOEXCEPT_RETURN( + _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...) +) + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr _Tp make_from_tuple(_Tuple&& __t) +_LIBCPP_NOEXCEPT_RETURN( + _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t), + typename __make_tuple_indices>>::type{}) +) + +#undef _LIBCPP_NOEXCEPT_RETURN + +#endif // _LIBCPP_STD_VER > 14 + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_TUPLE diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/apply.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/apply.pass.cpp new file mode 100644 index 0000000..2e82194 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/apply.pass.cpp @@ -0,0 +1,275 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// template constexpr decltype(auto) apply(F &&, T &&) + +// Test with different ref/ptr/cv qualified argument types. + +#include +#include +#include +#include + +#include "test_macros.h" +#include "type_id.h" + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + + +constexpr int constexpr_sum_fn() { return 0; } + +template +constexpr int constexpr_sum_fn(int x1, Ints... rest) { return x1 + constexpr_sum_fn(rest...); } + +struct ConstexprSumT { + constexpr ConstexprSumT() = default; + template + constexpr int operator()(Ints... values) const { + return constexpr_sum_fn(values...); + } +}; + + +void test_constexpr_evaluation() +{ + constexpr ConstexprSumT sum_obj{}; + { + using Tup = std::tuple<>; + using Fn = int(&)(); + constexpr Tup t; + static_assert(std::apply(static_cast(constexpr_sum_fn), t) == 0, ""); + static_assert(std::apply(sum_obj, t) == 0, ""); + } + { + using Tup = std::tuple; + using Fn = int(&)(int); + constexpr Tup t(42); + static_assert(std::apply(static_cast(constexpr_sum_fn), t) == 42, ""); + static_assert(std::apply(sum_obj, t) == 42, ""); + } + { + using Tup = std::tuple; + using Fn = int(&)(int, int); + constexpr Tup t(42, 101); + static_assert(std::apply(static_cast(constexpr_sum_fn), t) == 143, ""); + static_assert(std::apply(sum_obj, t) == 143, ""); + } + { + using Tup = std::pair; + using Fn = int(&)(int, int); + constexpr Tup t(42, 101); + static_assert(std::apply(static_cast(constexpr_sum_fn), t) == 143, ""); + static_assert(std::apply(sum_obj, t) == 143, ""); + } + { + using Tup = std::tuple; + using Fn = int(&)(int, int, int); + constexpr Tup t(42, 101, -1); + static_assert(std::apply(static_cast(constexpr_sum_fn), t) == 142, ""); + static_assert(std::apply(sum_obj, t) == 142, ""); + } + { + using Tup = std::array; + using Fn = int(&)(int, int, int); + constexpr Tup t = {42, 101, -1}; + static_assert(std::apply(static_cast(constexpr_sum_fn), t) == 142, ""); + static_assert(std::apply(sum_obj, t) == 142, ""); + } +} + + +enum CallQuals { + CQ_None, + CQ_LValue, + CQ_ConstLValue, + CQ_RValue, + CQ_ConstRValue +}; + +template +struct CallInfo { + CallQuals quals; + TypeID const* arg_types; + Tuple args; + + template + CallInfo(CallQuals q, Args&&... xargs) + : quals(q), arg_types(&makeArgumentID()), args(std::forward(xargs)...) + {} +}; + +template +inline CallInfo()...))> +makeCallInfo(CallQuals quals, Args&&... args) { + return {quals, std::forward(args)...}; +} + +struct TrackedCallable { + + TrackedCallable() = default; + + template auto operator()(Args&&... xargs) & + { return makeCallInfo(CQ_LValue, std::forward(xargs)...); } + + template auto operator()(Args&&... xargs) const& + { return makeCallInfo(CQ_ConstLValue, std::forward(xargs)...); } + + template auto operator()(Args&&... xargs) && + { return makeCallInfo(CQ_RValue, std::forward(xargs)...); } + + template auto operator()(Args&&... xargs) const&& + { return makeCallInfo(CQ_ConstRValue, std::forward(xargs)...); } +}; + +template +void check_apply_quals_and_types(Tuple&& t) { + TypeID const* const expect_args = &makeArgumentID(); + TrackedCallable obj; + TrackedCallable const& cobj = obj; + { + auto ret = std::apply(obj, std::forward(t)); + assert(ret.quals == CQ_LValue); + assert(ret.arg_types == expect_args); + assert(ret.args == t); + } + { + auto ret = std::apply(cobj, std::forward(t)); + assert(ret.quals == CQ_ConstLValue); + assert(ret.arg_types == expect_args); + assert(ret.args == t); + } + { + auto ret = std::apply(std::move(obj), std::forward(t)); + assert(ret.quals == CQ_RValue); + assert(ret.arg_types == expect_args); + assert(ret.args == t); + } + { + auto ret = std::apply(std::move(cobj), std::forward(t)); + assert(ret.quals == CQ_ConstRValue); + assert(ret.arg_types == expect_args); + assert(ret.args == t); + } +} + +void test_call_quals_and_arg_types() +{ + TrackedCallable obj; + using Tup = std::tuple; + const int x = 42; + unsigned y = 101; + Tup t(-1, x, std::move(y)); + Tup const& ct = t; + check_apply_quals_and_types(t); + check_apply_quals_and_types(ct); + check_apply_quals_and_types(std::move(t)); + check_apply_quals_and_types(std::move(ct)); +} + + +struct NothrowMoveable { + NothrowMoveable() noexcept = default; + NothrowMoveable(NothrowMoveable const&) noexcept(false) {} + NothrowMoveable(NothrowMoveable&&) noexcept {} +}; + +template +struct TestNoexceptCallable { + template + NothrowMoveable operator()(Args...) const noexcept(IsNoexcept) { return {}; } +}; + +void test_noexcept() +{ + TestNoexceptCallable nec; + TestNoexceptCallable tc; + { + // test that the functions noexcept-ness is propagated + using Tup = std::tuple; + Tup t; + ASSERT_NOEXCEPT(std::apply(nec, t)); + ASSERT_NOT_NOEXCEPT(std::apply(tc, t)); + } + { + // test that the noexcept-ness of the argument conversions is checked. + using Tup = std::tuple; + Tup t; + ASSERT_NOT_NOEXCEPT(std::apply(nec, t)); + ASSERT_NOEXCEPT(std::apply(nec, std::move(t))); + } +} + +namespace ReturnTypeTest { + static int my_int = 42; + + template struct index {}; + + void f(index<0>) {} + + int f(index<1>) { return 0; } + + int & f(index<2>) { return static_cast(my_int); } + int const & f(index<3>) { return static_cast(my_int); } + int volatile & f(index<4>) { return static_cast(my_int); } + int const volatile & f(index<5>) { return static_cast(my_int); } + + int && f(index<6>) { return static_cast(my_int); } + int const && f(index<7>) { return static_cast(my_int); } + int volatile && f(index<8>) { return static_cast(my_int); } + int const volatile && f(index<9>) { return static_cast(my_int); } + + int * f(index<10>) { return static_cast(&my_int); } + int const * f(index<11>) { return static_cast(&my_int); } + int volatile * f(index<12>) { return static_cast(&my_int); } + int const volatile * f(index<13>) { return static_cast(&my_int); } + + template + void test() + { + using RawInvokeResult = decltype(f(index{})); + static_assert(std::is_same::value, ""); + using FnType = RawInvokeResult (*) (index); + FnType fn = f; + std::tuple> t; ((void)t); + using InvokeResult = decltype(std::apply(fn, t)); + static_assert(std::is_same::value, ""); + } +} // end namespace ReturnTypeTest + +void test_return_type() +{ + using ReturnTypeTest::test; + test<0, void>(); + test<1, int>(); + test<2, int &>(); + test<3, int const &>(); + test<4, int volatile &>(); + test<5, int const volatile &>(); + test<6, int &&>(); + test<7, int const &&>(); + test<8, int volatile &&>(); + test<9, int const volatile &&>(); + test<10, int *>(); + test<11, int const *>(); + test<12, int volatile *>(); + test<13, int const volatile *>(); +} + +int main() { + test_constexpr_evaluation(); + test_call_quals_and_arg_types(); + test_return_type(); + test_noexcept(); +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/apply_extended_types.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/apply_extended_types.pass.cpp new file mode 100644 index 0000000..02d7fe4 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/apply_extended_types.pass.cpp @@ -0,0 +1,426 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// template constexpr decltype(auto) apply(F &&, T &&) + +// Testing extended function types. The extended function types are those +// named by INVOKE but that are not actual callable objects. These include +// bullets 1-4 of invoke. + +#include +#include +#include +#include + +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + +int count = 0; + +struct A_int_0 +{ + A_int_0() : obj1(0){} + A_int_0(int x) : obj1(x) {} + int mem1() { return ++count; } + int mem2() const { return ++count; } + int const obj1; +}; + +struct A_int_1 +{ + A_int_1() {} + A_int_1(int) {} + int mem1(int x) { return count += x; } + int mem2(int x) const { return count += x; } +}; + +struct A_int_2 +{ + A_int_2() {} + A_int_2(int) {} + int mem1(int x, int y) { return count += (x + y); } + int mem2(int x, int y) const { return count += (x + y); } +}; + +template +struct A_wrap +{ + A_wrap() {} + A_wrap(int x) : m_a(x) {} + A & operator*() { return m_a; } + A const & operator*() const { return m_a; } + A m_a; +}; + +typedef A_wrap A_wrap_0; +typedef A_wrap A_wrap_1; +typedef A_wrap A_wrap_2; + + +template +struct A_base : public A +{ + A_base() : A() {} + A_base(int x) : A(x) {} +}; + +typedef A_base A_base_0; +typedef A_base A_base_1; +typedef A_base A_base_2; + + +template < + class Tuple, class ConstTuple + , class TuplePtr, class ConstTuplePtr + , class TupleWrap, class ConstTupleWrap + , class TupleBase, class ConstTupleBase + > +void test_ext_int_0() +{ + count = 0; + typedef A_int_0 T; + typedef A_wrap_0 Wrap; + typedef A_base_0 Base; + + typedef int(T::*mem1_t)(); + mem1_t mem1 = &T::mem1; + + typedef int(T::*mem2_t)() const; + mem2_t mem2 = &T::mem2; + + typedef int const T::*obj1_t; + obj1_t obj1 = &T::obj1; + + // member function w/ref + { + T a; + Tuple t{a}; + assert(1 == std::apply(mem1, t)); + assert(count == 1); + } + count = 0; + // member function w/pointer + { + T a; + TuplePtr t{&a}; + assert(1 == std::apply(mem1, t)); + assert(count == 1); + } + count = 0; + // member function w/base + { + Base a; + TupleBase t{a}; + assert(1 == std::apply(mem1, t)); + assert(count == 1); + } + count = 0; + // member function w/wrap + { + Wrap a; + TupleWrap t{a}; + assert(1 == std::apply(mem1, t)); + assert(count == 1); + } + count = 0; + // const member function w/ref + { + T const a; + ConstTuple t{a}; + assert(1 == std::apply(mem2, t)); + assert(count == 1); + } + count = 0; + // const member function w/pointer + { + T const a; + ConstTuplePtr t{&a}; + assert(1 == std::apply(mem2, t)); + assert(count == 1); + } + count = 0; + // const member function w/base + { + Base const a; + ConstTupleBase t{a}; + assert(1 == std::apply(mem2, t)); + assert(count == 1); + } + count = 0; + // const member function w/wrapper + { + Wrap const a; + ConstTupleWrap t{a}; + assert(1 == std::apply(mem2, t)); + assert(1 == count); + } + // member object w/ref + { + T a{42}; + Tuple t{a}; + assert(42 == std::apply(obj1, t)); + } + // member object w/pointer + { + T a{42}; + TuplePtr t{&a}; + assert(42 == std::apply(obj1, t)); + } + // member object w/base + { + Base a{42}; + TupleBase t{a}; + assert(42 == std::apply(obj1, t)); + } + // member object w/wrapper + { + Wrap a{42}; + TupleWrap t{a}; + assert(42 == std::apply(obj1, t)); + } +} + + +template < + class Tuple, class ConstTuple + , class TuplePtr, class ConstTuplePtr + , class TupleWrap, class ConstTupleWrap + , class TupleBase, class ConstTupleBase + > +void test_ext_int_1() +{ + count = 0; + typedef A_int_1 T; + typedef A_wrap_1 Wrap; + typedef A_base_1 Base; + + typedef int(T::*mem1_t)(int); + mem1_t mem1 = &T::mem1; + + typedef int(T::*mem2_t)(int) const; + mem2_t mem2 = &T::mem2; + + // member function w/ref + { + T a; + Tuple t{a, 2}; + assert(2 == std::apply(mem1, t)); + assert(count == 2); + } + count = 0; + // member function w/pointer + { + T a; + TuplePtr t{&a, 3}; + assert(3 == std::apply(mem1, t)); + assert(count == 3); + } + count = 0; + // member function w/base + { + Base a; + TupleBase t{a, 4}; + assert(4 == std::apply(mem1, t)); + assert(count == 4); + } + count = 0; + // member function w/wrap + { + Wrap a; + TupleWrap t{a, 5}; + assert(5 == std::apply(mem1, t)); + assert(count == 5); + } + count = 0; + // const member function w/ref + { + T const a; + ConstTuple t{a, 6}; + assert(6 == std::apply(mem2, t)); + assert(count == 6); + } + count = 0; + // const member function w/pointer + { + T const a; + ConstTuplePtr t{&a, 7}; + assert(7 == std::apply(mem2, t)); + assert(count == 7); + } + count = 0; + // const member function w/base + { + Base const a; + ConstTupleBase t{a, 8}; + assert(8 == std::apply(mem2, t)); + assert(count == 8); + } + count = 0; + // const member function w/wrapper + { + Wrap const a; + ConstTupleWrap t{a, 9}; + assert(9 == std::apply(mem2, t)); + assert(9 == count); + } +} + + +template < + class Tuple, class ConstTuple + , class TuplePtr, class ConstTuplePtr + , class TupleWrap, class ConstTupleWrap + , class TupleBase, class ConstTupleBase + > +void test_ext_int_2() +{ + count = 0; + typedef A_int_2 T; + typedef A_wrap_2 Wrap; + typedef A_base_2 Base; + + typedef int(T::*mem1_t)(int, int); + mem1_t mem1 = &T::mem1; + + typedef int(T::*mem2_t)(int, int) const; + mem2_t mem2 = &T::mem2; + + // member function w/ref + { + T a; + Tuple t{a, 1, 1}; + assert(2 == std::apply(mem1, t)); + assert(count == 2); + } + count = 0; + // member function w/pointer + { + T a; + TuplePtr t{&a, 1, 2}; + assert(3 == std::apply(mem1, t)); + assert(count == 3); + } + count = 0; + // member function w/base + { + Base a; + TupleBase t{a, 2, 2}; + assert(4 == std::apply(mem1, t)); + assert(count == 4); + } + count = 0; + // member function w/wrap + { + Wrap a; + TupleWrap t{a, 2, 3}; + assert(5 == std::apply(mem1, t)); + assert(count == 5); + } + count = 0; + // const member function w/ref + { + T const a; + ConstTuple t{a, 3, 3}; + assert(6 == std::apply(mem2, t)); + assert(count == 6); + } + count = 0; + // const member function w/pointer + { + T const a; + ConstTuplePtr t{&a, 3, 4}; + assert(7 == std::apply(mem2, t)); + assert(count == 7); + } + count = 0; + // const member function w/base + { + Base const a; + ConstTupleBase t{a, 4, 4}; + assert(8 == std::apply(mem2, t)); + assert(count == 8); + } + count = 0; + // const member function w/wrapper + { + Wrap const a; + ConstTupleWrap t{a, 4, 5}; + assert(9 == std::apply(mem2, t)); + assert(9 == count); + } +} + +int main() +{ + { + test_ext_int_0< + std::tuple, std::tuple + , std::tuple, std::tuple + , std::tuple, std::tuple + , std::tuple, std::tuple + >(); + test_ext_int_0< + std::tuple, std::tuple + , std::tuple, std::tuple + , std::tuple, std::tuple + , std::tuple, std::tuple + >(); + test_ext_int_0< + std::array, std::array + , std::array, std::array + , std::array, std::array + , std::array, std::array + >(); + } + { + test_ext_int_1< + std::tuple, std::tuple + , std::tuple, std::tuple + , std::tuple, std::tuple + , std::tuple, std::tuple + >(); + test_ext_int_1< + std::tuple, std::tuple + , std::tuple, std::tuple + , std::tuple, std::tuple + , std::tuple, std::tuple + >(); + test_ext_int_1< + std::pair, std::pair + , std::pair, std::pair + , std::pair, std::pair + , std::pair, std::pair + >(); + test_ext_int_1< + std::pair, std::pair + , std::pair, std::pair + , std::pair, std::pair + , std::pair, std::pair + >(); + } + { + test_ext_int_2< + std::tuple, std::tuple + , std::tuple, std::tuple + , std::tuple, std::tuple + , std::tuple, std::tuple + >(); + test_ext_int_2< + std::tuple, std::tuple + , std::tuple, std::tuple + , std::tuple, std::tuple + , std::tuple, std::tuple + >(); + } +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/apply_large_arity.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/apply_large_arity.pass.cpp new file mode 100644 index 0000000..33c3ef5 --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/apply_large_arity.pass.cpp @@ -0,0 +1,144 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// template constexpr decltype(auto) apply(F &&, T &&) + +// Stress testing large arities with tuple and array. + +#include +#include +#include +#include + +//////////////////////////////////////////////////////////////////////////////// +template +struct always_imp +{ + typedef T type; +}; + +template +using always_t = typename always_imp::type; + +//////////////////////////////////////////////////////////////////////////////// +template +struct make_function; + +template +struct make_function> +{ + using type = bool (*)(always_t...); +}; + +template +using make_function_t = typename make_function>::type; + +//////////////////////////////////////////////////////////////////////////////// +template +struct make_tuple_imp; + +//////////////////////////////////////////////////////////////////////////////// +template +struct make_tuple_imp> +{ + using type = std::tuple...>; +}; + +template +using make_tuple_t = typename make_tuple_imp>::type; + +template +bool test_apply_fn(Types...) { return true; } + + +template +void test_all() +{ + + using A = std::array; + using ConstA = std::array; + + using Tuple = make_tuple_t; + using CTuple = make_tuple_t; + + using ValFn = make_function_t; + ValFn val_fn = &test_apply_fn; + + using RefFn = make_function_t; + RefFn ref_fn = &test_apply_fn; + + using CRefFn = make_function_t; + CRefFn cref_fn = &test_apply_fn; + + using RRefFn = make_function_t; + RRefFn rref_fn = &test_apply_fn; + + { + A a{}; + assert(std::apply(val_fn, a)); + assert(std::apply(ref_fn, a)); + assert(std::apply(cref_fn, a)); + assert(std::apply(rref_fn, std::move(a))); + } + { + ConstA a{}; + assert(std::apply(val_fn, a)); + assert(std::apply(cref_fn, a)); + } + { + Tuple a{}; + assert(std::apply(val_fn, a)); + assert(std::apply(ref_fn, a)); + assert(std::apply(cref_fn, a)); + assert(std::apply(rref_fn, std::move(a))); + } + { + CTuple a{}; + assert(std::apply(val_fn, a)); + assert(std::apply(cref_fn, a)); + } + +} + + +template +void test_one() +{ + using A = std::array; + using Tuple = make_tuple_t; + + using ValFn = make_function_t; + ValFn val_fn = &test_apply_fn; + + { + A a{}; + assert(std::apply(val_fn, a)); + } + { + Tuple a{}; + assert(std::apply(val_fn, a)); + } +} + +int main() +{ + // Instantiate with 1-5 arguments. + test_all<1>(); + test_all<2>(); + test_all<3>(); + test_all<4>(); + test_all<5>(); + + // Stress test with 256 + test_one<256>(); +} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.pass.cpp new file mode 100644 index 0000000..6d5cc2b --- /dev/null +++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.pass.cpp @@ -0,0 +1,210 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// template constexpr T make_from_tuple(Tuple&&); + +#include +#include +#include +#include +#include + +#include "test_macros.h" +#include "type_id.h" + +template +struct ConstexprConstructibleFromTuple { + template + explicit constexpr ConstexprConstructibleFromTuple(Args&&... xargs) + : args{std::forward(xargs)...} {} + Tuple args; +}; + +template +struct ConstructibleFromTuple; + +template