C++ Logo


Advanced search

C++ Object Tokens

From: Viktor Kireev <vitech-job_at_[hidden]>
Date: Wed, 29 Jan 2020 20:10:19 +0300
C++ Object Token Library

The C++ Object Token Library (CppOtl) provides a set of tokens that are
designed to manage an object's lifetime, similar to smart pointers from the
C++ standard library. CppOtl contains tokens for unique and shared
ownership of objects, weak observers for them, adds a unified type of
ownership. Also, it introduces tokens with single (not_null) multiplicity,
which can mitigate the "null references: billion-dollar mistake".

Tokens from CppOtl are integrated with smart pointers from the C++ standard
library and can be consistently converted from one to another. CppOtl is
intended for cases when there is not enough functionality of smart pointers
from the C++ standard library and additional capabilities are required.

1. A set of consistent tokens that can express associative links, function
parameters and variables according to a UML model.
2. `single` tokens that always have a linked object and can not be empty.
3. `trackable` and `untrackable` tokens for appropriate use-case
4. The `safe::weak` can be created both from the `safe::unique` and the
`safe::shared`. It will become `expired` (but not `dangling`) when an owner
of a watched object is destroyed.
5. The `safe::unified` can temporarily prolong an object's lifetime in a
given scope that allows finishing work with an object even other tokens is
6. A constructor with the `itself` parameter allows a token itself to
create an object with given attributes.
7. Algorithms for unified access to object tokens.
8. Tokens meet the requirements of `std::ranges::range`, that allows to
pass them to functions that accept `range` argument.
9. Traits allow recognizing characteristics of tokens in compile-time.
10. Focusing on maximum error detection in compile-time, several assertions
in a debug build, minimum overhead in a release build, avoiding exceptions.
11. The ability to create other token classes with required
12. The ability to integrate CppOtl tokens with third-party pointers and

The main difference of the safe::unique, safe::shared, safe::weak from the
std::unique_ptr, std::shared_ptr, std::weak_ptr that it is possible to
create the safe::weak both from the safe::unique and the safe::shared,
while the std::weak_ptr can be created only from the std::shared_ptr and
the std::unique_ptr does not have trackable weak counterpart.

The raw::unified and raw::weak are wrappers over raw C++ pointers. They are
represented to explicitly express single and optional multiplicity because
the raw pointer T* is not single (it can be nullptr) nor optional (after
move operation it is not "empty").

Please read more documentation on the

Is there any interest in such tokens? In the C++ standard library or a
standalone library.

Victor Kireev

Received on 2020-01-29 11:12:58