|
generic_iterators
1.0.0
Demonstration of implementing and using type safe generic iterators in pure, standard C
|
Utilities to define and use a Maybe type. More...

Go to the source code of this file.
Macros | |
| #define | Maybe(T) Maybe##T |
| Convenience macro to get the type of the Maybe defined with a certain type. More... | |
| #define | DefineMaybe(T) |
| Define a Maybe<T> type. More... | |
| #define | Just(v, T) ((Maybe(T)){.tag = MaybeTag_Just, .val = (v)}) |
Wrap a Just value into a Maybe(T). More... | |
| #define | Nothing(T) ((Maybe(T)){0}) |
Wrap a Nothing value into a Maybe(T). More... | |
| #define | is_nothing(x) ((x).tag == MaybeTag_Nothing) |
Check if the given Maybe type is tagged with Nothing. More... | |
| #define | is_just(x) ((x).tag == MaybeTag_Just) |
Check if the given Maybe type is tagged with Just. More... | |
| #define | from_just(x, T) T##_from_just(x) |
Extract the Just value from given Maybe(T). More... | |
| #define | from_just_(x) (x).val |
| "Unsafe" version of from_just(x, T). More... | |
Enumerations | |
| enum | MaybeTag { MaybeTag_Nothing = 0 , MaybeTag_Just } |
Utilities to define and use a Maybe type.
from_just or from_just_ after is_just/is_nothing instead. | #define DefineMaybe | ( | T | ) |
Define a Maybe<T> type.
| T | The type of value this Maybe will hold. Must be alphanumeric. |
T is a pointer, it needs to be typedef-ed into a type that does not contain the *. Only alphanumerics. | #define from_just | ( | x, | |
| T | |||
| ) | T##_from_just(x) |
Extract the Just value from given Maybe(T).
| x | The Maybe type to extract the value from. |
| T | The type of value the Maybe will hold. Must be alphanumeric. |
Just value of type corresponding to the given Maybe(T) if it's not Nothing.T is a pointer, it needs to be typedef-ed into a type that does not contain the *. Only alphanumerics. Nothing. | #define from_just_ | ( | x | ) | (x).val |
"Unsafe" version of from_just(x, T).
| x | The Maybe type to extract the value from. |
Just value of type corresponding to the given Maybe struct.Maybe struct actually has a value and hence should only be used when the caller is sure that the Maybe contains a Just value. Otherwise the behavior is undefined. | #define is_just | ( | x | ) | ((x).tag == MaybeTag_Just) |
Check if the given Maybe type is tagged with Just.
| x | The Maybe(T) struct to check against. |
| #define is_nothing | ( | x | ) | ((x).tag == MaybeTag_Nothing) |
Check if the given Maybe type is tagged with Nothing.
| x | The Maybe(T) struct to check against. |
| #define Just | ( | v, | |
| T | |||
| ) | ((Maybe(T)){.tag = MaybeTag_Just, .val = (v)}) |
Wrap a Just value into a Maybe(T).
| v | The concrete value to wrap in Just (must be of the correct type). |
| T | The type of value the Maybe will hold. Must be alphanumeric. |
T is a pointer, it needs to be typedef-ed into a type that does not contain the *. Only alphanumerics. | #define Maybe | ( | T | ) | Maybe##T |
Convenience macro to get the type of the Maybe defined with a certain type.
| T | The type of value the Maybe struct will contain. Must be the same type name passed to DefineMaybe(T). |
T is a pointer, it needs to be typedef-ed into a type that does not contain the *. Only alphanumerics. | #define Nothing | ( | T | ) | ((Maybe(T)){0}) |
Wrap a Nothing value into a Maybe(T).
| T | The type of value the Maybe will hold. Must be alphanumeric. |
T is a pointer, it needs to be typedef-ed into a type that does not contain the *. Only alphanumerics. | enum MaybeTag |