Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
types.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include <list>
5
#include <set>
6
#include <string>
7
#include <map>
8
#include <variant>
9
#include <vector>
10
11
namespace
nix {
12
13
typedef
std::list<std::string> Strings;
14
26
using
StringMap
= std::map<std::string, std::string, std::less<>>;
32
using
StringPairs
=
StringMap
;
33
45
using
StringSet
= std::set<std::string, std::less<>>;
46
47
typedef
std::vector<std::pair<std::string, std::string>> Headers;
48
52
template
<
typename
T>
53
struct
OnStartup
54
{
55
OnStartup(T && t)
56
{
57
t();
58
}
59
};
60
65
template
<
typename
T>
66
struct
Explicit
67
{
68
T t;
69
70
auto
operator<=>(
const
Explicit<T>
& other)
const
=
default
;
71
};
72
83
class
BackedStringView
84
{
85
private
:
86
std::variant<std::string, std::string_view> data;
87
93
class
Ptr
94
{
95
private
:
96
std::string_view view;
97
public
:
98
Ptr(std::string_view view)
99
: view(view)
100
{
101
}
102
103
const
std::string_view * operator->()
const
104
{
105
return
&view;
106
}
107
};
108
109
public
:
110
BackedStringView(std::string && s)
111
: data(std::move(s))
112
{
113
}
114
115
BackedStringView(std::string_view sv)
116
: data(sv)
117
{
118
}
119
120
template
<
size_t
N>
121
BackedStringView(
const
char
(&lit)[N])
122
: data(std::string_view(lit))
123
{
124
}
125
126
BackedStringView(
const
BackedStringView &) =
delete
;
127
BackedStringView & operator=(
const
BackedStringView &) =
delete
;
128
133
BackedStringView
(BackedStringView && other) =
default
;
134
BackedStringView & operator=(BackedStringView && other) =
default
;
135
136
bool
isOwned()
const
137
{
138
return
std::holds_alternative<std::string>(data);
139
}
140
141
std::string toOwned() &&
142
{
143
return
isOwned() ? std::move(std::get<std::string>(data)) : std::string(std::
get
<std::string_view>(data));
144
}
145
146
std::string_view operator*()
const
147
{
148
return
isOwned() ? std::get<std::string>(data) : std::get<std::string_view>(data);
149
}
150
151
Ptr operator->()
const
152
{
153
return
Ptr(**
this
);
154
}
155
};
156
157
}
// namespace nix
nix::BackedStringView::BackedStringView
BackedStringView(BackedStringView &&other)=default
nix::Explicit
Definition
types.hh:67
nix::StringMap
std::map< std::string, std::string, std::less<> > StringMap
Definition
types.hh:26
nix::StringPairs
StringMap StringPairs
Definition
types.hh:32
nix::StringSet
std::set< std::string, std::less<> > StringSet
Definition
types.hh:45
nix::get
const T * get(const std::optional< T > &opt)
Definition
util.hh:286
libutil
include
nix
util
types.hh
Generated by
1.18.0