Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
static-string-data.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include "
nix/expr/value.hh
"
5
6
namespace
nix {
7
8
template
<
size_t
N>
9
struct
StringData::Static
10
{
14
const
size_t
size
= N - 1;
15
char
data[N];
16
17
consteval
Static(
const
char
(&str)[N])
18
{
19
static_assert
(N > 0);
20
if
(str[
size
] !=
'\0'
)
21
throw
;
22
std::copy_n(str, N, data);
23
}
24
25
operator
const
StringData &()
const
&
26
{
27
static_assert
(
sizeof
(
decltype
(*this)) >=
sizeof
(StringData));
28
static_assert
(
alignof
(
decltype
(*this)) ==
alignof
(StringData));
29
/* NOTE: This cast is somewhat on the fence of what's legal in C++.
30
The question boils down to whether flexible array members are
31
layout compatible with fixed-size arrays. This is a gray area, since
32
FAMs are not standard anyway.
33
*/
34
return
*
reinterpret_cast<
const
StringData *
>
(
this
);
35
}
36
};
37
38
template
<StringData::Static S>
39
const
StringData &
operator
""
_sds()
40
{
41
return
S;
42
}
43
44
}
// namespace nix
nix::StringData::Static
Definition
static-string-data.hh:10
nix::StringData::Static::size
const size_t size
Definition
static-string-data.hh:14
value.hh
libexpr
include
nix
expr
static-string-data.hh
Generated by
1.18.0