| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
C++23 modular primitives library - import mcpplibs.primitives;
| 中文 - English - Forum |
|---|
| 用户文档 - User Documentation |
| API文档 - API Documentation |
This repository provides configurable primitive infrastructure (underlying traits, policy, and operations/dispatcher) to unify numeric behavior, error handling, and concurrency access semantics.
Warning
The project is still evolving quickly, and APIs may change.
The library provides unary, arithmetic, bitwise, and comparison operations for primitive.
Arithmetic paths are dispatched through a unified pipeline and return std::expected<..., policy::error::kind>.
Example:
import std;
import mcpplibs.primitives;
using namespace mcpplibs::primitives;
using namespace mcpplibs::primitives::operators;
primitive<int> a{1};
primitive<int> b{2};
auto sum = a + b; // std::expected<primitive<int>, policy::error::kind>
using checked_t =
primitive<int, policy::value::checked, policy::error::expected>;
auto maybe_overflow =
checked_t{std::numeric_limits<int>::max()} + checked_t{1};When implementing custom policies, protocol entry points are split by responsibility:
Built-in policy tags:
Concurrency notes:
Example (concurrent access APIs):
using shared_t = primitive<int, policy::value::checked,
policy::concurrency::fenced_acq_rel,
policy::error::expected>;
shared_t v{1};
v.store(2);
auto expected = 2;
if (v.compare_exchange(expected, 3)) {
auto now = v.load();
(void)now;
}Default policies are available under policy::defaults:
mcpplibs-primitives/ ├── src/ # module sources │ ├── primitives.cppm # top-level aggregate module │ ├── primitive/ # primitive definitions and traits │ ├── policy/ # policy tags and protocol implementations │ ├── operations/ # operation tags / dispatcher / operators │ └── underlying/ # underlying traits and common_rep ├── examples/ # example programs ├── tests/ # test entry and basic test suite ├── xmake.lua # xmake build script ├── CMakeLists.txt # CMake build script └── .xlings.json # xlings package descriptor
import std;
import mcpplibs.primitives;
int main() {
using namespace mcpplibs::primitives;
using value_t = primitive<int, policy::error::expected>;
auto const result = operations::add(value_t{40}, value_t{2});
return (result.has_value() && result->value() == 42) ? 0 : 1;
}xlings installUsing xmake
xmake build mcpplibs-primitives
xmake run basic # compatibility alias for ex01_basic_usage
xmake run ex01_basic_usage
xmake run ex06_conversion
xmake run ex07_algorithms
xmake run ex05_concurrency_policy
xmake run primitives_testUsing CMake (CMake >= 3.31)
cmake -B build -G Ninja
cmake --build build --target mcpplibs-primitives
cmake --build build --target ex01_basic_usage
cmake --build build --target ex06_conversion
cmake --build build --target ex07_algorithms
cmake --build build --target basic_tests
ctest --test-dir build --output-on-failureadd_repositories("mcpplibs-index https://github.com/mcpplibs/mcpplibs-index.git")
add_requires("primitives")
target("myapp")
set_kind("binary")
set_languages("c++23")
add_files("main.cpp")
add_packages("primitives")
set_policy("build.c++.modules", true)| Back | FazBrowse Home | New Git URL |