llvm-project/libc/utils/CPP/Functional.h
Alex Brachet 54d13b5b2d [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
2020-04-14 03:27:10 -04:00

31 lines
929 B
C++

//===-- 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