diff options
| author | Tyge Løvset <[email protected]> | 2021-12-14 22:28:45 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-12-14 22:28:45 +0100 |
| commit | fb8b06d933510add5f530d265a687899828d4904 (patch) | |
| tree | 40f18361dbb1ca5a0d17be59a2d60b9f5c1b0caf /docs | |
| parent | 9b83dd92e4ea590406ded5276b44cd83b4cf3b86 (diff) | |
| download | STC-modified-fb8b06d933510add5f530d265a687899828d4904.tar.gz STC-modified-fb8b06d933510add5f530d265a687899828d4904.zip | |
Some more docs updates and new csptr examples.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/cbox_api.md | 18 | ||||
| -rw-r--r-- | docs/ccommon_api.md | 2 |
2 files changed, 11 insertions, 9 deletions
diff --git a/docs/cbox_api.md b/docs/cbox_api.md index 1f10928d..83cec830 100644 --- a/docs/cbox_api.md +++ b/docs/cbox_api.md @@ -1,15 +1,17 @@ -# STC [cbox](../include/stc/cbox.h): Shared Pointers +# STC [cbox](../include/stc/cbox.h): (Boxed) Heap Allocated Objects -**cbox** is a container for one heap allocated object. A **cbox** is empty by default. -The *cbox_X_compare()*, *cbox_X_del()* methods are defined based on the `i_cmp` -and `i_valdel` macros specified. Use *cbox_X_clone(p)* to make a deep copy, which -uses the `i_valfrom` macro if defined. +**cbox** is a A box is a smart pointer to a heap allocated value of type X. A **cbox** can +be empty. The *cbox_X_compare()*, *cbox_X_del()* methods are defined based on the `i_cmp` +and `i_valdel` macros specified. Use *cbox_X_clone(p)* to make a deep copy, which uses the +`i_valfrom` macro if defined. -When declaring a container with cbox elements, define `i_val_ref` as the cbox type, see example. +When declaring a container of **cbox** values, it is recommended to define `i_val_ref` to the +cbox type instead of defining `i_val`. This will auto-set `i_del`, `i_from`, and `i_cmp` using +functions defined by the specified **cbox**. For containers, make sure to pass the result of create functions like *cbox_X_new()* **only** to -*insert()*, *push_back()*, and *push()* functions. Use *emplace()* functions to deep clone -already existing/owned cbox elements. +*insert()*, *push_back()*, and *push()* functions. Use the *emplace()* functions in order to +auto-*clone* an already existing/owned cbox element. See similar c++ class [std::unique_ptr](https://en.cppreference.com/w/cpp/memory/unique_ptr) for a functional reference, or Rust [std::boxed::Box](https://doc.rust-lang.org/std/boxed/struct.Box.html) diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index 4dc099fb..12609eeb 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -85,7 +85,7 @@ int main() |:-------------------------------------------|:--------------------------------| | `c_foreach (it, ctype, container)` | Iteratate all elements | | `c_foreach (it, ctype, it1, it2)` | Iterate the range [it1, it2) | -| `c_forpair (key, value, ctype, container)` | Iterate with structural binding | +| `c_forpair (key, value, ctype, container)` | Iterate with structured binding | ```c #define i_key int |
