1//===- llvm/ADT/STLFunctionalExtras.h - Extras for <functional> -*- C++ -*-===//
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
7//===----------------------------------------------------------------------===//
9// This file contains some extension to <functional>.
11// No library is required when using these functions.
13//===----------------------------------------------------------------------===//
15#ifndef LLVM_ADT_STLFUNCTIONALEXTRAS_H
16#define LLVM_ADT_STLFUNCTIONALEXTRAS_H
27//===----------------------------------------------------------------------===//
28// Extra additions to <functional>
29//===----------------------------------------------------------------------===//
31/// An efficient, type-erasing, non-owning reference to a callable. This is
32/// intended for use as the type of a function parameter that is not used
33/// after the function in question returns.
35/// This class does not own the callable, so it is not in general safe to store
39template <
typename Ret,
typename... Params>
41 Ret (*callback)(intptr_t callable, Params ...params) =
nullptr;
44 template<
typename Callable>
45 static Ret callback_fn(intptr_t callable, Params ...params) {
46 return (*
reinterpret_cast<Callable*
>(callable))(
47 std::forward<Params>(params)...);
54 template <
typename Callable>
57 // This is not the copy-constructor.
60 // Functor must be callable and return a suitable type.
61 std::enable_if_t<std::is_void<Ret>::value ||
62 std::is_convertible<
decltype(std::declval<Callable>()(
63 std::declval<Params>()...)),
64 Ret>::value> * =
nullptr)
65 : callback(callback_fn<
std::remove_reference_t<Callable>>),
66 callable(reinterpret_cast<intptr_t>(&callable)) {}
69 return callback(callable, std::forward<Params>(params)...);
72 explicit operator bool()
const {
return callback; }
75 return callable ==
Other.callable;
79}
// end namespace llvm
81#endif // LLVM_ADT_STLFUNCTIONALEXTRAS_H
#define LLVM_LIFETIME_BOUND
#define LLVM_GSL_POINTER
LLVM_GSL_POINTER - Apply this to non-owning classes like StringRef to enable lifetime warnings.
This file contains library features backported from future STL versions.
bool operator==(const function_ref< Ret(Params...)> &Other) const
function_ref(Callable &&callable LLVM_LIFETIME_BOUND, std::enable_if_t<!std::is_same< remove_cvref_t< Callable >, function_ref >::value > *=nullptr, std::enable_if_t< std::is_void< Ret >::value||std::is_convertible< decltype(std::declval< Callable >()(std::declval< Params >()...)), Ret >::value > *=nullptr)
function_ref(std::nullptr_t)
Ret operator()(Params ...params) const
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
Implement std::hash so that hash_code can be used in STL containers.