compat.tl-optional
#includetl::optional — std::optional with monadic operations and reference support (header-only)
#include <tl/optional.hpp>
mcpp add compat.tl-optional@1.1.0
Usage
From this repository's own test project — built and run by CI, not written for the website.
// compat.tl-optional — assert value/empty state, observers, mutation, monadic
// chaining, reference binding, and constexpr construction through the public
// header. The test uses only the standard library in addition to tl/optional.
#include <tl/optional.hpp>
#include <cstdio>
#include <string>
#include <type_traits>
int main() {
bool ok = true;
auto check = [&](bool condition, const char* what) {
if (!condition) {
std::printf("FAIL: %s\n", what);
ok = false;
}
};
tl::optional<int> value = tl::make_optional(42);
tl::optional<int> empty = tl::nullopt;
check(value.has_value() && *value == 42, "value construction and observer");
check(!empty.has_value(), "nullopt constructs an empty optional");
// …
tests/examples/tl-optional/tests/optional.cpp · project tests/examples/tl-optional
Build
- targets
optional (lib)- language
c++23- C standard
c11- import std
- no
- include dirs
*/include
Sources (1)
mcpp_generated/tl_optional_anchor.c
Generated files
mcpp_generated/tl_optional_anchor.c