Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
fun.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include <functional>
5
#include <stdexcept>
6
#include <type_traits>
7
#include <utility>
8
9
namespace
nix {
10
18
template
<
typename
Sig>
19
class
fun
;
20
21
template
<
typename
Ret,
typename
...
Args
>
22
class
fun
<Ret(
Args
...)>
23
{
24
private
:
25
26
std::function<Ret(
Args
...)> f;
27
28
void
assertCallable()
29
{
30
if
(!f)
31
throw
std::invalid_argument(
"null callable cast to fun"
);
32
}
33
34
public
:
35
36
using
result_type = Ret;
37
44
template
<
typename
F>
45
requires
(
46
!std::is_same_v<std::decay_t<F>,
fun
> && !std::is_same_v<std::decay_t<F>, std::function<Ret(
Args
...)>>
47
&& !std::is_same_v<std::decay_t<F>, std::nullptr_t>
48
&& std::is_constructible_v<std::function<Ret(
Args
...)>, F>)
49
fun
(F && callable)
50
: f(std::forward<F>(callable))
51
{
52
assertCallable();
53
}
54
59
explicit
fun
(
const
std::function<Ret(
Args
...)> & fn)
60
: f(fn)
61
{
62
assertCallable();
63
}
64
65
explicit
fun
(std::function<Ret(
Args
...)> && fn)
66
: f(std::move(fn))
67
{
68
assertCallable();
69
}
70
72
fun
(std::nullptr_t) =
delete
;
73
74
template
<
typename
... Ts>
75
Ret operator()(Ts &&... args)
const
76
{
77
return
f(std::forward<Ts>(args)...);
78
}
79
81
const
std::function<Ret(
Args
...)> &
get_fn
() const &
82
{
83
return
f;
84
}
85
86
std::function<Ret(
Args
...)> get_fn() &&
87
{
88
return
std::move(f);
89
}
90
};
91
92
}
// namespace nix
nix::Args
Definition
args.hh:29
nix::fun< Ret(Args...)>::fun
fun(F &&callable)
Definition
fun.hh:49
nix::fun< Ret(Args...)>::get_fn
const std::function< Ret(Args...)> & get_fn() const &
Definition
fun.hh:81
nix::fun< Ret(Args...)>::fun
fun(std::nullptr_t)=delete
nix::fun< Ret(Args...)>::fun
fun(const std::function< Ret(Args...)> &fn)
Definition
fun.hh:59
nix::fun
Definition
fun.hh:19
libutil
include
nix
util
fun.hh
Generated by
1.18.0