[libc++] Remove redundant __invoke_constexpr functions

There are `constexpr` versions for the different `__invoke` functions, which seem to be identical other than begin `constexpr` since C++11 instead of being `constexpr` since C++20.

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D123003
This commit is contained in:
Nikolas Klauser 2022-04-06 23:10:21 +02:00
parent 82d0f7bdb5
commit 1b9c5f60aa
6 changed files with 63 additions and 188 deletions

View File

@ -1609,7 +1609,7 @@ inline _LIBCPP_INLINE_VISIBILITY
constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
__tuple_indices<_Id...>)
_LIBCPP_NOEXCEPT_RETURN(
_VSTD::__invoke_constexpr(
_VSTD::__invoke(
_VSTD::forward<_Fn>(__f),
_VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
)

View File

@ -3460,139 +3460,74 @@ using __enable_if_bullet6 = typename enable_if
template <class ..._Args>
auto __invoke(__any, _Args&& ...__args) -> __nat;
template <class ..._Args>
auto __invoke_constexpr(__any, _Args&& ...__args) -> __nat;
// bullets 1, 2 and 3
template <class _Fp, class _A0, class ..._Args,
class = __enable_if_bullet1<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
constexpr auto
__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
noexcept(noexcept((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...)))
-> decltype( (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
{ return (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...); }
template <class _Fp, class _A0, class ..._Args,
class = __enable_if_bullet1<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR auto
__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
noexcept(noexcept((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...)))
-> decltype( (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
{ return (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...); }
template <class _Fp, class _A0, class ..._Args,
class = __enable_if_bullet2<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
constexpr auto
__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
noexcept(noexcept((__a0.get().*__f)(static_cast<_Args&&>(__args)...)))
-> decltype( (__a0.get().*__f)(static_cast<_Args&&>(__args)...))
{ return (__a0.get().*__f)(static_cast<_Args&&>(__args)...); }
template <class _Fp, class _A0, class ..._Args,
class = __enable_if_bullet2<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR auto
__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
noexcept(noexcept((__a0.get().*__f)(static_cast<_Args&&>(__args)...)))
-> decltype( (__a0.get().*__f)(static_cast<_Args&&>(__args)...))
{ return (__a0.get().*__f)(static_cast<_Args&&>(__args)...); }
template <class _Fp, class _A0, class ..._Args,
class = __enable_if_bullet3<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
constexpr auto
__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
noexcept(noexcept(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...)))
-> decltype( ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
{ return ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...); }
template <class _Fp, class _A0, class ..._Args,
class = __enable_if_bullet3<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR auto
__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
noexcept(noexcept(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...)))
-> decltype( ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
{ return ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...); }
// bullets 4, 5 and 6
template <class _Fp, class _A0,
class = __enable_if_bullet4<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
constexpr auto
__invoke(_Fp&& __f, _A0&& __a0)
noexcept(noexcept(static_cast<_A0&&>(__a0).*__f))
-> decltype( static_cast<_A0&&>(__a0).*__f)
{ return static_cast<_A0&&>(__a0).*__f; }
template <class _Fp, class _A0,
class = __enable_if_bullet4<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR auto
__invoke_constexpr(_Fp&& __f, _A0&& __a0)
noexcept(noexcept(static_cast<_A0&&>(__a0).*__f))
-> decltype( static_cast<_A0&&>(__a0).*__f)
{ return static_cast<_A0&&>(__a0).*__f; }
template <class _Fp, class _A0,
class = __enable_if_bullet5<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
constexpr auto
__invoke(_Fp&& __f, _A0&& __a0)
noexcept(noexcept(__a0.get().*__f))
-> decltype( __a0.get().*__f)
{ return __a0.get().*__f; }
template <class _Fp, class _A0,
class = __enable_if_bullet5<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR auto
__invoke_constexpr(_Fp&& __f, _A0&& __a0)
noexcept(noexcept(__a0.get().*__f))
-> decltype( __a0.get().*__f)
{ return __a0.get().*__f; }
template <class _Fp, class _A0,
class = __enable_if_bullet6<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
constexpr auto
__invoke(_Fp&& __f, _A0&& __a0)
noexcept(noexcept((*static_cast<_A0&&>(__a0)).*__f))
-> decltype( (*static_cast<_A0&&>(__a0)).*__f)
{ return (*static_cast<_A0&&>(__a0)).*__f; }
template <class _Fp, class _A0,
class = __enable_if_bullet6<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR auto
__invoke_constexpr(_Fp&& __f, _A0&& __a0)
noexcept(noexcept((*static_cast<_A0&&>(__a0)).*__f))
-> decltype( (*static_cast<_A0&&>(__a0)).*__f)
{ return (*static_cast<_A0&&>(__a0)).*__f; }
// bullet 7
template <class _Fp, class ..._Args>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
constexpr auto
__invoke(_Fp&& __f, _Args&& ...__args)
noexcept(noexcept(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...)))
-> decltype( static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
{ return static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
template <class _Fp, class ..._Args>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR auto
__invoke_constexpr(_Fp&& __f, _Args&& ...__args)
noexcept(noexcept(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...)))
-> decltype( static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
{ return static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
// __invokable
template <class _Ret, class _Fp, class ..._Args>
struct __invokable_r

View File

@ -547,7 +547,7 @@ private:
template <class _Fp, class... _Vs>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr decltype(auto) __dispatch(_Fp __f, _Vs... __vs) {
return _VSTD::__invoke_constexpr(
return _VSTD::__invoke(
static_cast<_Fp>(__f),
__access::__base::__get_alt<_Is>(static_cast<_Vs>(__vs))...);
}
@ -667,8 +667,8 @@ private:
__std_visit_exhaustive_visitor_check<
_Visitor,
decltype((_VSTD::forward<_Alts>(__alts).__value))...>();
return _VSTD::__invoke_constexpr(_VSTD::forward<_Visitor>(__visitor),
_VSTD::forward<_Alts>(__alts).__value...);
return _VSTD::__invoke(_VSTD::forward<_Visitor>(__visitor),
_VSTD::forward<_Alts>(__alts).__value...);
}
_Visitor&& __visitor;
};
@ -683,12 +683,12 @@ private:
_Visitor,
decltype((_VSTD::forward<_Alts>(__alts).__value))...>();
if constexpr (is_void_v<_Rp>) {
_VSTD::__invoke_constexpr(_VSTD::forward<_Visitor>(__visitor),
_VSTD::forward<_Alts>(__alts).__value...);
_VSTD::__invoke(_VSTD::forward<_Visitor>(__visitor),
_VSTD::forward<_Alts>(__alts).__value...);
}
else {
return _VSTD::__invoke_constexpr(_VSTD::forward<_Visitor>(__visitor),
_VSTD::forward<_Alts>(__alts).__value...);
return _VSTD::__invoke(_VSTD::forward<_Visitor>(__visitor),
_VSTD::forward<_Alts>(__alts).__value...);
}
}

View File

@ -244,30 +244,55 @@ struct TestCase : public TestCaseImp<MemFun03, Sig, Arity, CV> {};
#if TEST_STD_VER >= 11
template <class Sig, int Arity, class CV, bool RValue = false>
struct TestCase11 : public TestCaseImp<MemFun11, Sig, Arity, CV, RValue, true> {};
#endif
template <class Tp>
struct DerivedFromRefWrap : public std::reference_wrapper<Tp> {
DerivedFromRefWrap(Tp& tp) : std::reference_wrapper<Tp>(tp) {}
template <class Type>
struct ReferenceWrapper {
using type = Type;
Type* ptr;
static void fun(Type&) noexcept;
static void fun(Type&&) = delete;
template <class Type2,
class = typename std::enable_if<!std::__is_same_uncvref<Type2, ReferenceWrapper>::value>::type>
constexpr ReferenceWrapper(Type2&& t) noexcept : ptr(&t) {}
constexpr Type& get() const noexcept { return *ptr; }
constexpr operator Type&() const noexcept { return *ptr; }
template <class... _ArgTypes>
constexpr typename std::__invoke_of<Type&, _ArgTypes...>::type operator() (_ArgTypes&&... __args) const {
return std::__invoke(get(), std::forward<_ArgTypes>(__args)...);
}
};
#if TEST_STD_VER >= 11
void test_derived_from_ref_wrap() {
template <class Tp>
struct DerivedFromRefWrap : public ReferenceWrapper<Tp> {
constexpr DerivedFromRefWrap(Tp& tp) : ReferenceWrapper<Tp>(tp) {}
};
TEST_CONSTEXPR_CXX14 bool test_derived_from_ref_wrap() {
int x = 42;
ReferenceWrapper<int> r(x);
DerivedFromRefWrap<int> d(x);
auto get_fn = &ReferenceWrapper<int>::get;
auto& ret = std::__invoke(get_fn, r);
assert(&ret == &x);
auto& ret2 = std::__invoke(get_fn, d);
assert(&ret2 == &x);
return true;
}
TEST_CONSTEXPR_CXX20 bool test_reference_wrapper_reference_wrapper() {
int x = 42;
auto get_fn = &std::reference_wrapper<int>::get;
std::reference_wrapper<int> r(x);
std::reference_wrapper<std::reference_wrapper<int>> r2(r);
DerivedFromRefWrap<int> d(x);
auto get_fn = &std::reference_wrapper<int>::get;
auto& ret = std::__invoke(get_fn, r);
auto& cret = std::__invoke_constexpr(get_fn, r);
assert(&ret == &x);
assert(&cret == &x);
auto& ret2 = std::__invoke(get_fn, d);
auto& cret2 = std::__invoke_constexpr(get_fn, d);
assert(&ret2 == &x);
assert(&cret2 == &x);
auto& ret3 = std::__invoke(get_fn, r2);
assert(&ret3 == &x);
return true;
}
#endif
@ -366,7 +391,14 @@ int main(int, char**) {
TestCase11<R(A&&, A&&, A&&, ...) const volatile &&, 3, Q_CV, /* RValue */ true>::run();
test_derived_from_ref_wrap();
test_reference_wrapper_reference_wrapper();
#if TEST_STD_VER > 11
static_assert(test_derived_from_ref_wrap(), "");
#endif
#if TEST_STD_VER > 17
static_assert(test_reference_wrapper_reference_wrapper(), "");
#endif
#endif // TEST_STD_VER >= 11
return 0;
}

View File

@ -195,21 +195,9 @@ private:
Expect e = std::__invoke(M, std::forward<T>(obj));
assert(&e == expect);
}
#if TEST_STD_VER >= 11
{
static_assert((std::is_same<
decltype(std::__invoke_constexpr(M, std::forward<T>(obj))), Expect
>::value), "");
Expect e = std::__invoke_constexpr(M, std::forward<T>(obj));
assert(&e == expect);
}
#endif
}
};
int main(int, char**) {
TestCase<ArgType>::run();
TestCase<ArgType const>::run();

View File

@ -282,16 +282,6 @@ private:
CallRet ret = std::__invoke(ptr, object_cast(object));
assert(ID::checkCalled(ret));
}
#if TEST_STD_VER >= 11
{
static_assert((std::is_same<
decltype(std::__invoke_constexpr(ptr, object_cast(object)))
, CallRet>::value), "");
assert(ID::unchecked_call == false);
CallRet ret = std::__invoke_constexpr(ptr, object_cast(object));
assert(ID::checkCalled(ret));
}
#endif
}
template <class MethodPtr, class ObjectT>
@ -304,16 +294,6 @@ private:
CallRet ret = std::__invoke(ptr, object_cast(object), arg_cast(a0));
assert(ID::checkCalled(ret));
}
#if TEST_STD_VER >= 11
{
static_assert((std::is_same<
decltype(std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0)))
, CallRet>::value), "");
assert(ID::unchecked_call == false);
CallRet ret = std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0));
assert(ID::checkCalled(ret));
}
#endif
}
template <class MethodPtr, class ObjectT>
@ -326,16 +306,6 @@ private:
CallRet ret = std::__invoke(ptr, object_cast(object), arg_cast(a0), arg_cast(a1));
assert(ID::checkCalled(ret));
}
#if TEST_STD_VER >= 11
{
static_assert((std::is_same<
decltype(std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0), arg_cast(a1)))
, CallRet>::value), "");
assert(ID::unchecked_call == false);
CallRet ret = std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0), arg_cast(a1));
assert(ID::checkCalled(ret));
}
#endif
}
template <class MethodPtr, class ObjectT>
@ -348,16 +318,6 @@ private:
CallRet ret = std::__invoke(ptr, object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2));
assert(ID::checkCalled(ret));
}
#if TEST_STD_VER >= 11
{
static_assert((std::is_same<
decltype(std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2)))
, CallRet>::value), "");
assert(ID::unchecked_call == false);
CallRet ret = std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2));
assert(ID::checkCalled(ret));
}
#endif
}
//==========================================================================
@ -373,16 +333,6 @@ private:
CallRet ret = std::__invoke(object_cast(object));
assert(ID::checkCalled(ret));
}
#if TEST_STD_VER >= 11
{
static_assert((std::is_same<
decltype(std::__invoke_constexpr(object_cast(object)))
, CallRet>::value), "");
assert(ID::unchecked_call == false);
CallRet ret = std::__invoke_constexpr(object_cast(object));
assert(ID::checkCalled(ret));
}
#endif
}
template <class ObjectT>
@ -395,16 +345,6 @@ private:
CallRet ret = std::__invoke(object_cast(object), arg_cast(a0));
assert(ID::checkCalled(ret));
}
#if TEST_STD_VER >= 11
{
static_assert((std::is_same<
decltype(std::__invoke_constexpr(object_cast(object), arg_cast(a0)))
, CallRet>::value), "");
assert(ID::unchecked_call == false);
CallRet ret = std::__invoke_constexpr(object_cast(object), arg_cast(a0));
assert(ID::checkCalled(ret));
}
#endif
}
template <class ObjectT>
@ -417,16 +357,6 @@ private:
CallRet ret = std::__invoke(object_cast(object), arg_cast(a0), arg_cast(a1));
assert(ID::checkCalled(ret));
}
#if TEST_STD_VER >= 11
{
static_assert((std::is_same<
decltype(std::__invoke_constexpr(object_cast(object), arg_cast(a0), arg_cast(a1)))
, CallRet>::value), "");
assert(ID::unchecked_call == false);
CallRet ret = std::__invoke_constexpr(object_cast(object), arg_cast(a0), arg_cast(a1));
assert(ID::checkCalled(ret));
}
#endif
}
template <class ObjectT>
@ -439,16 +369,6 @@ private:
CallRet ret = std::__invoke(object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2));
assert(ID::checkCalled(ret));
}
#if TEST_STD_VER >= 11
{
static_assert((std::is_same<
decltype(std::__invoke_constexpr(object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2)))
, CallRet>::value), "");
assert(ID::unchecked_call == false);
CallRet ret = std::__invoke_constexpr(object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2));
assert(ID::checkCalled(ret));
}
#endif
}
};