Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
STLFunctionalExtras.h
Go to the documentation of this file.
1//===- llvm/ADT/STLFunctionalExtras.h - Extras for <functional> -*- 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// This file contains some extension to <functional>.
10//
11// No library is required when using these functions.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_ADT_STLFUNCTIONALEXTRAS_H
16#define LLVM_ADT_STLFUNCTIONALEXTRAS_H
17
18#include "llvm/ADT/STLForwardCompat.h"
19#include "llvm/Support/Compiler.h"
20
21#include <cstdint>
22#include <type_traits>
23#include <utility>
24
25namespacellvm {
26
27//===----------------------------------------------------------------------===//
28// Extra additions to <functional>
29//===----------------------------------------------------------------------===//
30
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.
34///
35/// This class does not own the callable, so it is not in general safe to store
36/// a function_ref.
37template<typename Fn>classfunction_ref;
38
39template <typename Ret,typename... Params>
40classLLVM_GSL_POINTERfunction_ref<Ret(Params...)> {
41 Ret (*callback)(intptr_t callable, Params ...params) =nullptr;
42 intptr_t callable;
43
44template<typename Callable>
45static Ret callback_fn(intptr_t callable, Params ...params) {
46return (*reinterpret_cast<Callable*>(callable))(
47 std::forward<Params>(params)...);
48 }
49
50public:
51function_ref() =default;
52function_ref(std::nullptr_t) {}
53
54template <typename Callable>
55function_ref(
56 Callable &&callableLLVM_LIFETIME_BOUND,
57// This is not the copy-constructor.
58 std::enable_if_t<!std::is_same<remove_cvref_t<Callable>,
59function_ref>::value> * =nullptr,
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)) {}
67
68 Retoperator()(Params ...params) const{
69return callback(callable, std::forward<Params>(params)...);
70 }
71
72explicitoperatorbool() const{return callback; }
73
74booloperator==(constfunction_ref<Ret(Params...)> &Other) const{
75return callable ==Other.callable;
76 }
77};
78
79}// end namespace llvm
80
81#endif// LLVM_ADT_STLFUNCTIONALEXTRAS_H
Compiler.h
LLVM_LIFETIME_BOUND
#define LLVM_LIFETIME_BOUND
Definition:Compiler.h:419
LLVM_GSL_POINTER
#define LLVM_GSL_POINTER
LLVM_GSL_POINTER - Apply this to non-owning classes like StringRef to enable lifetime warnings.
Definition:Compiler.h:413
value
Given that RA is a live value
Definition:DeadArgumentElimination.cpp:716
Other
std::optional< std::vector< StOtherPiece > > Other
Definition:ELFYAML.cpp:1315
STLForwardCompat.h
This file contains library features backported from future STL versions.
bool
llvm::function_ref< Ret(Params...)>::operator==
bool operator==(const function_ref< Ret(Params...)> &Other) const
Definition:STLFunctionalExtras.h:74
llvm::function_ref< Ret(Params...)>::function_ref
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)
Definition:STLFunctionalExtras.h:55
llvm::function_ref< Ret(Params...)>::function_ref
function_ref(std::nullptr_t)
Definition:STLFunctionalExtras.h:52
llvm::function_ref< Ret(Params...)>::operator()
Ret operator()(Params ...params) const
Definition:STLFunctionalExtras.h:68
llvm::function_ref< Ret(Params...)>::function_ref
function_ref()=default
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition:STLFunctionalExtras.h:37
remove_cvref_t
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
std
Implement std::hash so that hash_code can be used in STL containers.
Definition:BitVector.h:858

Generated on Thu Jul 17 2025 08:14:12 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp