Graphviz
14.1.4~dev.20260320.0055
Loading...
Searching...
No Matches
optional.h
Go to the documentation of this file.
1
3
4
#pragma once
5
6
#include <assert.h>
7
#include <stdbool.h>
8
#include <stddef.h>
9
#include <stdio.h>
10
#include <stdlib.h>
11
13
#define OPTIONAL(type) \
14
struct { \
15
bool has_value; \
16
type value_; \
17
}
18
26
#define OPTIONAL_SET(me, value) \
27
do { \
28
assert((me) != NULL); \
29
(me)->has_value = true; \
30
(me)->value_ = (value); \
31
} while (0)
32
39
#define OPTIONAL_VALUE(me) \
40
(((me).has_value ? (void)0 \
41
: (fprintf(stderr, \
42
"%s:%d: internal error: attempted to read the " \
43
"value of an empty optional type\n", \
44
__FILE__, __LINE__), \
45
abort())), \
46
(me).value_)
47
53
#define OPTIONAL_VALUE_OR(me, fallback) \
54
((me).has_value ? (me).value_ : (fallback))
lib
util
optional.h
Generated by
1.9.8