From e5407178d6789ccf462dbb39ad0acc5cbde6581c Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Wed, 22 Jul 2015 04:14:38 +0000 Subject: [PATCH] Cleanup <__functional_03> <__functional_03> provides the C++03 definitions for std::memfun and std::function. However the interaction between and <__functional_03> is ugly and duplicates code needlessly. This patch cleans up how the two headers work together. The major changes are: - Provide placeholders, is_bind_expression and is_placeholder in for both C++03 and C++11. - Provide bad_function_call, function fwd decl, __maybe_derive_from_unary_function and __maybe_derive_from_binary_function in for both C++03 and C++11. - Move the <__functional_03> include to the bottom of . This makes it easier to see how <__functional_03> interacts with - Remove a commented out implementation of bind in C++03. It's never going to get implemented. - Mark almost all std::bind tests as unsupported in C++03. std::is_placeholder works in C++03 and C++11. std::is_bind_expression is provided in C++03 but always returns false. llvm-svn: 242870 --- libcxx/include/__functional_03 | 304 +----------------- libcxx/include/functional | 42 ++- .../func.bind/func.bind.bind/copy.pass.cpp | 2 + .../invoke_function_object.pass.cpp | 2 + .../func.bind.bind/invoke_int_0.pass.cpp | 2 + .../func.bind.bind/invoke_lvalue.pass.cpp | 2 + .../func.bind.bind/invoke_rvalue.pass.cpp | 2 + .../func.bind.bind/invoke_void_0.pass.cpp | 2 + .../func.bind/func.bind.bind/nested.pass.cpp | 2 + .../is_bind_expression.pass.cpp | 2 + .../is_bind_expression_03.pass.cpp | 39 +++ 11 files changed, 92 insertions(+), 309 deletions(-) create mode 100644 libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression_03.pass.cpp diff --git a/libcxx/include/__functional_03 b/libcxx/include/__functional_03 index 13c38d8548d9..bf55e23482f1 100644 --- a/libcxx/include/__functional_03 +++ b/libcxx/include/__functional_03 @@ -196,39 +196,7 @@ mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) const volatile) return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const volatile>(__pm); } -// bad_function_call - -class _LIBCPP_EXCEPTION_ABI bad_function_call - : public exception -{ -}; - -template class _LIBCPP_TYPE_VIS_ONLY function; // undefined - -namespace __function -{ - -template -struct __maybe_derive_from_unary_function -{ -}; - -template -struct __maybe_derive_from_unary_function<_Rp(_A1)> - : public unary_function<_A1, _Rp> -{ -}; - -template -struct __maybe_derive_from_binary_function -{ -}; - -template -struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> - : public binary_function<_A1, _A2, _Rp> -{ -}; +namespace __function { template class __base; @@ -1856,274 +1824,4 @@ void swap(function<_Fp>& __x, function<_Fp>& __y) {return __x.swap(__y);} -template struct __is_bind_expression : public false_type {}; -template struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression - : public __is_bind_expression::type> {}; - -template struct __is_placeholder : public integral_constant {}; -template struct _LIBCPP_TYPE_VIS_ONLY is_placeholder - : public __is_placeholder::type> {}; - -namespace placeholders -{ - -template struct __ph {}; - -extern __ph<1> _1; -extern __ph<2> _2; -extern __ph<3> _3; -extern __ph<4> _4; -extern __ph<5> _5; -extern __ph<6> _6; -extern __ph<7> _7; -extern __ph<8> _8; -extern __ph<9> _9; -extern __ph<10> _10; - -} // placeholders - -template -struct __is_placeholder > - : public integral_constant {}; - -template -inline _LIBCPP_INLINE_VISIBILITY -_Tp& -__mu(reference_wrapper<_Tp> __t, _Uj&) -{ - return __t.get(); -} -/* -template -struct __mu_return1 {}; - -template -struct __mu_return1 -{ - typedef typename result_of<_Ti(_Uj...)>::type type; -}; - -template -inline _LIBCPP_INLINE_VISIBILITY -typename __mu_return1::type -__mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>) -{ - __ti(_VSTD::forward::type>(_VSTD::get<_Indx>(__uj))...); -} - -template -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_bind_expression<_Ti>::value, - typename __mu_return1::value, _Ti, _Uj...>::type ->::type -__mu(_Ti& __ti, tuple<_Uj...>& __uj) -{ - typedef typename __make_tuple_indices::type __indices; - return __mu_expand(__ti, __uj, __indices()); -} - -template -struct __mu_return2 {}; - -template -struct __mu_return2 -{ - typedef typename tuple_element::value - 1, _Uj>::type type; -}; - -template -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - 0 < is_placeholder<_Ti>::value, - typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type ->::type -__mu(_Ti&, _Uj& __uj) -{ - const size_t _Indx = is_placeholder<_Ti>::value - 1; - // compiler bug workaround - typename tuple_element<_Indx, _Uj>::type __t = _VSTD::get<_Indx>(__uj); - return __t; -// return _VSTD::forward::type>(_VSTD::get<_Indx>(__uj)); -} - -template -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_bind_expression<_Ti>::value && - is_placeholder<_Ti>::value == 0 && - !__is_reference_wrapper<_Ti>::value, - _Ti& ->::type -__mu(_Ti& __ti, _Uj& __uj) -{ - return __ti; -} - -template -struct ____mu_return; - -template -struct ____mu_return<_Ti, true, false, tuple<_Uj...> > -{ - typedef typename result_of<_Ti(_Uj...)>::type type; -}; - -template -struct ____mu_return<_Ti, false, true, _TupleUj> -{ - typedef typename tuple_element::value - 1, - _TupleUj>::type&& type; -}; - -template -struct ____mu_return<_Ti, false, false, _TupleUj> -{ - typedef _Ti& type; -}; - -template -struct __mu_return - : public ____mu_return<_Ti, - is_bind_expression<_Ti>::value, - 0 < is_placeholder<_Ti>::value, - _TupleUj> -{ -}; - -template -struct __mu_return, _TupleUj> -{ - typedef _Ti& type; -}; - -template -struct __bind_return; - -template -struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> -{ - typedef typename __ref_return - < - _Fp&, - typename __mu_return - < - _BoundArgs, - _TupleUj - >::type... - >::type type; -}; - -template -struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> -{ - typedef typename __ref_return - < - _Fp&, - typename __mu_return - < - const _BoundArgs, - _TupleUj - >::type... - >::type type; -}; - -template -inline _LIBCPP_INLINE_VISIBILITY -typename __bind_return<_Fp, _BoundArgs, _Args>::type -__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, - _Args&& __args) -{ - return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...); -} - -template -class __bind -{ - _Fp __f_; - tuple<_BoundArgs...> __bound_args_; - - typedef typename __make_tuple_indices::type __indices; -public: - template - explicit __bind(_Gp&& __f, _BA&& ...__bound_args) - : __f_(_VSTD::forward<_Gp>(__f)), - __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} - - template - typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type - operator()(_Args&& ...__args) - { - // compiler bug workaround - return __apply_functor(__f_, __bound_args_, __indices(), - tuple<_Args&&...>(__args...)); - } - - template - typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type - operator()(_Args&& ...__args) const - { - return __apply_functor(__f_, __bound_args_, __indices(), - tuple<_Args&&...>(__args...)); - } -}; - -template -struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; - -template -class __bind_r - : public __bind<_Fp, _BoundArgs...> -{ - typedef __bind<_Fp, _BoundArgs...> base; -public: - typedef _Rp result_type; - - template - explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) - : base(_VSTD::forward<_Gp>(__f), - _VSTD::forward<_BA>(__bound_args)...) {} - - template - result_type - operator()(_Args&& ...__args) - { - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(static_cast(*this), _VSTD::forward<_Args>(__args)...); - } - - template - result_type - operator()(_Args&& ...__args) const - { - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(static_cast(*this), _VSTD::forward<_Args>(__args)...); - } -}; - -template -struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; - -template -inline _LIBCPP_INLINE_VISIBILITY -__bind::type, typename decay<_BoundArgs>::type...> -bind(_Fp&& __f, _BoundArgs&&... __bound_args) -{ - typedef __bind::type, typename decay<_BoundArgs>::type...> type; - return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); -} - -template -inline _LIBCPP_INLINE_VISIBILITY -__bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> -bind(_Fp&& __f, _BoundArgs&&... __bound_args) -{ - typedef __bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type; - return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); -} -*/ - #endif // _LIBCPP_FUNCTIONAL_03 diff --git a/libcxx/include/functional b/libcxx/include/functional index 9bed783153ef..2c4a96ed2bab 100644 --- a/libcxx/include/functional +++ b/libcxx/include/functional @@ -1234,11 +1234,11 @@ const_mem_fun1_ref_t<_Sp,_Tp,_Ap> mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} -#ifdef _LIBCPP_HAS_NO_VARIADICS +//////////////////////////////////////////////////////////////////////////////// +// MEMFUN +//============================================================================== -#include <__functional_03> - -#else // _LIBCPP_HAS_NO_VARIADICS +#ifndef _LIBCPP_HAS_NO_VARIADICS template class __mem_fn @@ -1271,6 +1271,12 @@ mem_fn(_Rp _Tp::* __pm) return __mem_fn<_Rp _Tp::*>(__pm); } +#endif // _LIBCPP_HAS_NO_VARIADICS + +//////////////////////////////////////////////////////////////////////////////// +// FUNCTION +//============================================================================== + // bad_function_call class _LIBCPP_EXCEPTION_ABI bad_function_call @@ -1283,7 +1289,7 @@ template class _LIBCPP_TYPE_VIS_ONLY function; // undefined namespace __function { -template +template struct __maybe_derive_from_unary_function { }; @@ -1294,7 +1300,7 @@ struct __maybe_derive_from_unary_function<_Rp(_A1)> { }; -template +template struct __maybe_derive_from_binary_function { }; @@ -1305,6 +1311,12 @@ struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> { }; +} // namespace __function + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +namespace __function { + template class __base; template @@ -1848,6 +1860,12 @@ void swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT {return __x.swap(__y);} +#endif // _LIBCPP_HAS_NO_VARIADICS + +//////////////////////////////////////////////////////////////////////////////// +// BIND +//============================================================================== + template struct __is_bind_expression : public false_type {}; template struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression : public __is_bind_expression::type> {}; @@ -1878,6 +1896,9 @@ template struct __is_placeholder > : public integral_constant {}; + +#ifndef _LIBCPP_HAS_NO_VARIADICS + template inline _LIBCPP_INLINE_VISIBILITY _Tp& @@ -2458,6 +2479,15 @@ invoke(_Fn&& __f, _Args&&... __args) { // struct hash in + +//////////////////////////////////////////////////////////////////////////////// +// FUNCTIONAL 03 +//============================================================================== + +#ifdef _LIBCPP_HAS_NO_VARIADICS +#include <__functional_03> +#endif + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_FUNCTIONAL diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp index 6315598125c9..ad03e8fb6bb2 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03 + // // template diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp index 33bf01855908..4577d0bf4d54 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03 + // // template diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp index ab4dd59534d5..815096f6b157 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_int_0.pass.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03 + // // template diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp index af5efe464d5d..f69afbf57667 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03 + // // template diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp index 4913a510c36e..a1137ee388c1 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_rvalue.pass.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03 + // // template diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp index b7874b77cf03..73f26e4b585a 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03 + // // template diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp index 12720f7b550a..f61d93aefd89 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03 + // // template diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp index 7f8dd4a98d2b..83fa452fecb3 100644 --- a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression.pass.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03 + // // template struct is_bind_expression diff --git a/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression_03.pass.cpp b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression_03.pass.cpp new file mode 100644 index 000000000000..12a78dbc7548 --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.isbind/is_bind_expression_03.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +//----------------------------------------------------------------------------- +// TESTING template struct is_bind_expression +// +// bind is not implemented in C++03 so nothing is a bind expression. However +// for compatibility reasons the trait is_bind_expression should be available +// in C++03 and it should always return false. + +#include + +template +void test() { + static_assert(!std::is_bind_expression::value, ""); +} + +struct C {}; + +int main() { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); +}