mcpp index

compat.type-safe

#include

Strongly typed wrappers and type-safe utility types for C++ (header-only)

#include <type_safe/optional.hpp>
mcpp add compat.type-safe@0.2.4

Usage

From this repository's own test project — built and run by CI, not written for the website.

#include <type_safe/optional.hpp>
#include <type_safe/strong_typedef.hpp>

#include <cstdio>
#include <type_traits>

struct user_id : type_safe::strong_typedef<user_id, int> {
    using strong_typedef::strong_typedef;
};

int main() {
    bool ok = true;
    auto check = [&](bool condition, const char* what) {
        if (!condition) {
            std::printf("FAIL: %s\n", what);
            ok = false;
        }
    };

    static_assert(!std::is_convertible<user_id, int>::value,
                  "strong typedefs must not implicitly convert to their representation");

// …

tests/examples/type-safe/tests/type_safe.cpp · project tests/examples/type-safe

Build

targets
type_safe (lib)
language
c++23
C standard
c11
import std
no
include dirs
*/include, */external/debug_assert

Sources (1)

  • mcpp_generated/type_safe_anchor.c

Generated files

  • mcpp_generated/type_safe_anchor.c

Versions

VersionPlatforms Mirrorssha256
0.2.4 latest LinuxWindowsmacOS CN GLOBAL a631d03c18c6…