forked from LadybirdBrowser/ladybird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunction.h
50 lines (38 loc) · 1.12 KB
/
Function.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Copyright (c) 2023, Andreas Kling <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Function.h>
#include <LibGC/Cell.h>
#include <LibGC/Heap.h>
namespace GC {
template<typename T>
class Function final : public Cell {
GC_CELL(Function, Cell);
public:
static Ref<Function> create(Heap& heap, ESCAPING AK::Function<T> function)
{
return heap.allocate<Function>(move(function));
}
virtual ~Function() override = default;
[[nodiscard]] AK::Function<T> const& function() const { return m_function; }
private:
Function(AK::Function<T> function)
: m_function(move(function))
{
}
virtual void visit_edges(Visitor& visitor) override
{
Base::visit_edges(visitor);
visitor.visit_possible_values(m_function.raw_capture_range());
}
AK::Function<T> m_function;
};
template<typename Callable, typename T = EquivalentFunctionType<Callable>>
static Ref<Function<T>> create_function(Heap& heap, ESCAPING Callable&& function)
{
return Function<T>::create(heap, AK::Function<T> { forward<Callable>(function) });
}
}