|
| 1 | +# Extension Guide |
| 2 | + |
| 3 | +This page covers extensibility paths used by advanced users. |
| 4 | + |
| 5 | +## 1) Custom Underlying Type |
| 6 | + |
| 7 | +Define a domain type and specialize `underlying::traits<T>`. |
| 8 | + |
| 9 | +Required members: |
| 10 | + |
| 11 | +- `value_type` |
| 12 | +- `rep_type` |
| 13 | +- `static constexpr bool enabled` |
| 14 | +- `static constexpr underlying::category kind` |
| 15 | +- `to_rep(value)` |
| 16 | +- `from_rep(rep)` |
| 17 | +- `is_valid_rep(rep)` |
| 18 | + |
| 19 | +After registration, your type can be used as `primitive<YourType, ...>` if it satisfies `underlying_type`. |
| 20 | + |
| 21 | +Reference example: `examples/ex06_custom_underlying.cpp`. |
| 22 | + |
| 23 | +## 2) Custom Common Rep Negotiation |
| 24 | + |
| 25 | +If default `std::common_type_t` is not suitable, specialize: |
| 26 | + |
| 27 | +```cpp |
| 28 | +template <> |
| 29 | +struct mcpplibs::primitives::underlying::common_rep_traits<LhsRep, RhsRep> { |
| 30 | + using type = YourCommonRep; |
| 31 | + static constexpr bool enabled = true; |
| 32 | +}; |
| 33 | +``` |
| 34 | +
|
| 35 | +This affects mixed dispatch and type negotiation. |
| 36 | +
|
| 37 | +## 3) Custom Policy Tags and Handlers |
| 38 | +
|
| 39 | +Custom policies require: |
| 40 | +
|
| 41 | +1. Registering tags via `policy::traits<YourPolicyTag>`. |
| 42 | +2. Providing protocol specializations in the correct namespaces: |
| 43 | + - `policy::type::handler` |
| 44 | + - `policy::value::handler` |
| 45 | + - `policy::error::handler` |
| 46 | + - `policy::concurrency::handler` |
| 47 | +
|
| 48 | +If your value policy needs operation runtime behavior, also provide `operations::runtime::op_binding` specializations. |
| 49 | +
|
| 50 | +Reference example: `examples/ex07_custom_policy.cpp`. |
| 51 | +
|
| 52 | +## 4) Custom Operation Tags |
| 53 | +
|
| 54 | +To add new operation tags: |
| 55 | +
|
| 56 | +1. Define operation tag type. |
| 57 | +2. Specialize `operations::traits<OpTag>` with: |
| 58 | + - `enabled = true` |
| 59 | + - `arity` |
| 60 | + - `capability_mask` |
| 61 | +3. Provide `operations::runtime::op_binding<OpTag, ValuePolicy, CommonRep>`. |
| 62 | +4. Invoke via `operations::apply<OpTag>(lhs, rhs)`. |
| 63 | +
|
| 64 | +Reference example: `examples/ex08_custom_operation.cpp`. |
| 65 | +
|
| 66 | +## Extension Checklist |
| 67 | +
|
| 68 | +- Policy groups are consistent across operands. |
| 69 | +- Operation capability metadata is valid. |
| 70 | +- Value policy + operation binding exists for runtime dispatch. |
| 71 | +- Error policy handler returns expected payload type. |
| 72 | +- Concurrency access handler exists if you need `load/store/CAS`. |
| 73 | +
|
| 74 | +## Next |
| 75 | +
|
| 76 | +- API details for protocol contracts: [../../api/en/README.md](../../api/en/README.md) |
| 77 | +
|
0 commit comments