1 //===-- Self contained functional header ------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_LIBC_UTILS_CPP_FUNCTIONAL_H 10 #define LLVM_LIBC_UTILS_CPP_FUNCTIONAL_H 11 12 namespace __llvm_libc { 13 namespace cpp { 14 15 template <typename Func> class Function; 16 17 template <typename Ret, typename... Params> class Function<Ret(Params...)> { 18 Ret (*func)(Params...) = nullptr; 19 20 public: 21 constexpr Function() = default; Function(Func && f)22 template <typename Func> constexpr Function(Func &&f) : func(f) {} 23 operator()24 constexpr Ret operator()(Params... params) { return func(params...); } 25 }; 26 27 } // namespace cpp 28 } // namespace __llvm_libc 29 30 #endif // LLVM_LIBC_UTILS_CPP_FUNCTIONAL_H 31