forked from activeloopai/deeplake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.hpp
More file actions
102 lines (80 loc) · 2.66 KB
/
Copy pathfunction.hpp
File metadata and controls
102 lines (80 loc) · 2.66 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once
/**
* @file function.hpp
* @brief Definition of the `function` class
*/
#include "source_location_holder.hpp"
#include <absl/functional/any_invocable.h>
namespace base {
#if defined(AL_ASSERTIONS) && !defined(AL_PG)
template <typename F>
class function_with_location;
template <typename R, typename... Args>
class function_with_location<R(Args...)> : public absl::AnyInvocable<R(Args...)>, public source_location_holder
{
public:
function_with_location(source_location location = source_location::current())
: source_location_holder(std::move(location))
{
}
template <typename Callable>
function_with_location(Callable&& callable, source_location location = source_location::current())
: absl::AnyInvocable<R(Args...)>(std::forward<Callable>(callable))
, source_location_holder(std::move(location))
{
}
template <typename Callable>
function_with_location& operator=(Callable&& callable)
{
absl::AnyInvocable<R(Args...)>::operator=(std::forward<Callable>(callable));
return *this;
}
function_with_location& operator=(std::nullptr_t)
{
absl::AnyInvocable<R(Args...)>::operator=(nullptr);
return *this;
}
using absl::AnyInvocable<R(Args...)>::operator();
explicit operator bool() const
{
return absl::AnyInvocable<R(Args...)>::operator bool();
}
};
template <typename R, typename... Args>
class function_with_location<R(Args...) const> : public absl::AnyInvocable<R(Args...) const>, public source_location_holder
{
public:
function_with_location(source_location location = source_location::current())
: source_location_holder(std::move(location))
{
}
template <typename Callable>
function_with_location(Callable&& callable, source_location location = source_location::current())
: absl::AnyInvocable<R(Args...) const>(std::forward<Callable>(callable))
, source_location_holder(std::move(location))
{
}
template <typename Callable>
function_with_location& operator=(Callable&& callable)
{
absl::AnyInvocable<R(Args...) const>::operator=(std::forward<Callable>(callable));
return *this;
}
function_with_location& operator=(std::nullptr_t)
{
absl::AnyInvocable<R(Args...) const>::operator=(nullptr);
return *this;
}
using absl::AnyInvocable<R(Args...) const>::operator();
explicit operator bool() const
{
return absl::AnyInvocable<R(Args...) const>::operator bool();
}
};
template <typename F>
using function = function_with_location<F>;
#else
template <typename F>
using function = absl::AnyInvocable<F>;
#endif
}