mcpp index

compat.tl-optional

#include

tl::optional — std::optional with monadic operations and reference support (header-only)

#include <tl/optional.hpp>
mcpp add compat.tl-optional@1.1.0

用法

来自本仓库自己的测试项目 —— CI 真的编译并运行过,不是为了网站写的。

// 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 · 项目 tests/examples/tl-optional

构建

targets
optional (lib)
language
c++23
C standard
c11
import std
no
include dirs
*/include

源文件 (1)

  • mcpp_generated/tl_optional_anchor.c

生成的文件

  • mcpp_generated/tl_optional_anchor.c

版本

版本平台 镜像sha256
1.1.0 最新 LinuxWindowsmacOS CN GLOBAL 88ece79f3de5…