mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-21 23:30:38 +08:00
[libcxx] P0604, invoke_result and is_invocable
Summary: Introduce a new form of `result_of` without function type encoding. Rename and split `is_callable/is_nothrow_callable` into `is_invocable/is_nothrow_invocable/is_invocable_r/is_nothrow_invocable_r` (and associated types accordingly) Change function type encoding of previous `is_callable/is_nothrow_callable` traits to conventional template type parameter lists. Reviewers: EricWF, mclow.lists, bebuch Reviewed By: EricWF, bebuch Subscribers: lichray, bebuch, cfe-commits Differential Revision: https://reviews.llvm.org/D38831 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@320509 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -438,26 +438,26 @@ void throws_in_constructor_test()
|
||||
void call_operator_sfinae_test() {
|
||||
{ // wrong number of arguments
|
||||
using T = decltype(std::not_fn(returns_true));
|
||||
static_assert(std::is_callable<T()>::value, ""); // callable only with no args
|
||||
static_assert(!std::is_callable<T(bool)>::value, "");
|
||||
static_assert(std::is_invocable<T>::value, ""); // callable only with no args
|
||||
static_assert(!std::is_invocable<T, bool>::value, "");
|
||||
}
|
||||
{ // violates const correctness (member function pointer)
|
||||
using T = decltype(std::not_fn(&MemFunCallable::return_value_nc));
|
||||
static_assert(std::is_callable<T(MemFunCallable&)>::value, "");
|
||||
static_assert(!std::is_callable<T(const MemFunCallable&)>::value, "");
|
||||
static_assert(std::is_invocable<T, MemFunCallable&>::value, "");
|
||||
static_assert(!std::is_invocable<T, const MemFunCallable&>::value, "");
|
||||
}
|
||||
{ // violates const correctness (call object)
|
||||
using Obj = CopyCallable<bool>;
|
||||
using NCT = decltype(std::not_fn(Obj{true}));
|
||||
using CT = const NCT;
|
||||
static_assert(std::is_callable<NCT()>::value, "");
|
||||
static_assert(!std::is_callable<CT()>::value, "");
|
||||
static_assert(std::is_invocable<NCT>::value, "");
|
||||
static_assert(!std::is_invocable<CT>::value, "");
|
||||
}
|
||||
{ // returns bad type with no operator!
|
||||
auto fn = [](auto x) { return x; };
|
||||
using T = decltype(std::not_fn(fn));
|
||||
static_assert(std::is_callable<T(bool)>::value, "");
|
||||
static_assert(!std::is_callable<T(std::string)>::value, "");
|
||||
static_assert(std::is_invocable<T, bool>::value, "");
|
||||
static_assert(!std::is_invocable<T, std::string>::value, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -32,7 +32,7 @@ int main()
|
||||
static_assert(!std::is_copy_assignable<H>::value, "");
|
||||
static_assert(!std::is_move_assignable<H>::value, "");
|
||||
#if TEST_STD_VER > 14
|
||||
static_assert(!std::is_callable<H(X&)>::value, "");
|
||||
static_assert(!std::is_callable<H(X const&)>::value, "");
|
||||
static_assert(!std::is_invocable<H, X&>::value, "");
|
||||
static_assert(!std::is_invocable<H, X const&>::value, "");
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user