本页面面向需要扩展库能力的用户。
定义业务类型后,特化 underlying::traits<T>。
必需成员:
value_typerep_typestatic constexpr bool enabledstatic constexpr underlying::category kindto_rep(value)from_rep(rep)is_valid_rep(rep)
完成后,只要满足 underlying_type,即可用于 primitive<YourType, ...>。
参考:examples/ex06_custom_underlying.cpp
当默认 std::common_type_t 不满足需求时,可特化:
template <>
struct mcpplibs::primitives::underlying::common_rep_traits<LhsRep, RhsRep> {
using type = YourCommonRep;
static constexpr bool enabled = true;
};这会影响 mixed dispatch 与 type negotiation。
自定义 policy 需要:
- 通过
policy::traits<YourPolicyTag>注册标签。 - 在对应命名空间提供协议特化:
policy::type::handlerpolicy::value::handlerpolicy::error::handlerpolicy::concurrency::handler
如果 value policy 需要参与运行期运算逻辑,还要补充 operations::runtime::op_binding 特化。
参考:examples/ex07_custom_policy.cpp
新增 operation 的典型步骤:
- 定义 operation tag 类型。
- 特化
operations::traits<OpTag>,设置:enabled = truearitycapability_mask
- 提供
operations::runtime::op_binding<OpTag, ValuePolicy, CommonRep>。 - 通过
operations::apply<OpTag>(lhs, rhs)调用。
参考:examples/ex08_custom_operation.cpp
- 双操作数策略组是否一致。
- operation capability 元信息是否正确。
- value policy + operation binding 是否覆盖运行期分发路径。
- error handler 返回类型是否匹配。
- 若需要
load/store/CAS,并发 access handler 是否实现。
- 协议契约与模板细节: ../../api/zh/README.md