[libc-commits] [libc] 54d13b5 - [libc] Remove <functional> dependency in syscall_test.cpp
Alex Brachet via libc-commits
libc-commits at lists.llvm.org
Tue Apr 14 00:27:21 PDT 2020
Author: Alex Brachet
Date: 2020-04-14T03:27:10-04:00
New Revision: 54d13b5b2d927652429b0538e27dcd28b783a302
URL: https://github.com/llvm/llvm-project/commit/54d13b5b2d927652429b0538e27dcd28b783a302
DIFF: https://github.com/llvm/llvm-project/commit/54d13b5b2d927652429b0538e27dcd28b783a302.diff
LOG: [libc] Remove <functional> dependency in syscall_test.cpp
Summary: Create self contained functional header which has a type similar to `std::function`
Reviewers: sivachandra, PaulkaToast
Reviewed By: sivachandra
Subscribers: mgorny, tschuett, libc-commits
Differential Revision: https://reviews.llvm.org/D77948
Added:
libc/utils/CPP/Functional.h
Modified:
libc/test/config/linux/x86_64/syscall_test.cpp
libc/utils/CPP/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/test/config/linux/x86_64/syscall_test.cpp b/libc/test/config/linux/x86_64/syscall_test.cpp
index 398ab5a1203c..b2487332947e 100644
--- 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 <functional>
+#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<long(long)> f([](long n) { return __llvm_libc::syscall(n); });
- std::function<long(long, long)> f1(
+ using __llvm_libc::cpp::function;
+
+ function<long(long)> f([](long n) { return __llvm_libc::syscall(n); });
+ function<long(long, long)> f1(
[](long n, long a1) { return __llvm_libc::syscall(n, a1); });
- std::function<long(long, long, long)> f2(
+ function<long(long, long, long)> f2(
[](long n, long a1, long a2) { return __llvm_libc::syscall(n, a1, a2); });
- std::function<long(long, long, long, long)> f3(
+ function<long(long, long, long, long)> f3(
[](long n, long a1, long a2, long a3) {
return __llvm_libc::syscall(n, a1, a2, a3);
});
- std::function<long(long, long, long, long, long)> f4(
+ function<long(long, long, long, long, long)> f4(
[](long n, long a1, long a2, long a3, long a4) {
return __llvm_libc::syscall(n, a1, a2, a3, a4);
});
- std::function<long(long, long, long, long, long, long)> f5(
+ function<long(long, long, long, long, long, long)> 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<long(long, long, long, long, long, long, long)> f6(
+ function<long(long, long, long, long, long, long, long)> 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<long(long, void *)> notLongType(
- [](long n, void *a1) {
- return __llvm_libc::syscall(n, a1);
- });
+ function<long(long, void *)> 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
index 5cbfec2498f8..4c7f5e9fce1a 100644
--- a/libc/utils/CPP/CMakeLists.txt
+++ b/libc/utils/CPP/CMakeLists.txt
@@ -3,5 +3,7 @@ add_header_library(
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
index 000000000000..70d3fe9867a8
--- /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 <typename Func> class function;
+
+template <typename Ret, typename... Params> class function<Ret(Params...)> {
+ Ret (*func)(Params...) = nullptr;
+
+public:
+ constexpr function() = default;
+ template <typename Func> 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
More information about the libc-commits
mailing list