diff --git a/libc/test/config/linux/x86_64/syscall_test.cpp b/libc/test/config/linux/x86_64/syscall_test.cpp --- a/libc/test/config/linux/x86_64/syscall_test.cpp +++ b/libc/test/config/linux/x86_64/syscall_test.cpp @@ -9,36 +9,36 @@ #include "config/linux/syscall.h" #include "utils/UnitTest/Test.h" -#include +#include "utils/CPP/Functional.h" TEST(X86_64_SyscallTest, APITest) { // We only do a signature test here. Actual functionality tests are // done by the unit tests of the syscall wrappers like mmap. - std::function f([](long n) { return __llvm_libc::syscall(n); }); - std::function f1( + using __llvm_libc::cpp::function; + + function f([](long n) { return __llvm_libc::syscall(n); }); + function f1( [](long n, long a1) { return __llvm_libc::syscall(n, a1); }); - std::function f2( + function f2( [](long n, long a1, long a2) { return __llvm_libc::syscall(n, a1, a2); }); - std::function f3( + function f3( [](long n, long a1, long a2, long a3) { return __llvm_libc::syscall(n, a1, a2, a3); }); - std::function f4( + function f4( [](long n, long a1, long a2, long a3, long a4) { return __llvm_libc::syscall(n, a1, a2, a3, a4); }); - std::function f5( + function f5( [](long n, long a1, long a2, long a3, long a4, long a5) { return __llvm_libc::syscall(n, a1, a2, a3, a4, a5); }); - std::function f6( + function f6( [](long n, long a1, long a2, long a3, long a4, long a5, long a6) { return __llvm_libc::syscall(n, a1, a2, a3, a4, a5, a6); }); - std::function notLongType( - [](long n, void *a1) { - return __llvm_libc::syscall(n, a1); - }); + function notLongType( + [](long n, void *a1) { return __llvm_libc::syscall(n, a1); }); } diff --git a/libc/utils/CPP/CMakeLists.txt b/libc/utils/CPP/CMakeLists.txt --- a/libc/utils/CPP/CMakeLists.txt +++ b/libc/utils/CPP/CMakeLists.txt @@ -3,5 +3,7 @@ HDRS Array.h ArrayRef.h + Functional.h + StringRef.h TypeTraits.h ) diff --git a/libc/utils/CPP/Functional.h b/libc/utils/CPP/Functional.h new file mode 100644 --- /dev/null +++ b/libc/utils/CPP/Functional.h @@ -0,0 +1,30 @@ +//===-- Self contained functional header ------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_UTILS_CPP_FUNCTIONAL_H +#define LLVM_LIBC_UTILS_CPP_FUNCTIONAL_H + +namespace __llvm_libc { +namespace cpp { + +template class function; + +template class function { + Ret (*func)(Params...) = nullptr; + +public: + constexpr function() = default; + template constexpr function(Func &&f) : func(f) {} + + constexpr Ret operator()(Params... params) { return func(params...); } +}; + +} // namespace cpp +} // namespace __llvm_libc + +#endif // LLVM_LIBC_UTILS_CPP_FUNCTIONAL_H