|
Flow 3.0.0
Flow project: Full implementation reference.
|
An integer-like, type-safe wrapper for the thread-token concept – see this_thread_unique_token(), which explains the whole situation and returns one of these; we are merely the type-safe type usable for it. More...
#include <uniq_id_holder.hpp>
Public Types | |
| using | id_t = Unique_id_holder::id_t |
| Short-hand for the underlying integer type. More... | |
Public Member Functions | |
| constexpr | operator id_t () const |
| Returns m_val; so comparisons and the like work as for an integer. More... | |
Public Attributes | |
| id_t | m_val = 0 |
The underlying integer value; 0 <=> "none." Typically it is better to assign to *this rather than to m_val. More... | |
Related Functions | |
(Note that these are not member functions.) | |
| std::ostream & | operator<< (std::ostream &os, Thread_token val) |
Prints string representation of the given Thread_token to the given ostream: the low 32 bits of the underlying integer in fixed-width hex – 0x followed by exactly N (as of this writing N=8) zero-padded digits – a token being an identity, not a quantity. More... | |
| size_t | hash_value (Thread_token val) |
Hashes the given Thread_token; making it, e.g., boost.unordered-compatible as a key out of the box. More... | |
An integer-like, type-safe wrapper for the thread-token concept – see this_thread_unique_token(), which explains the whole situation and returns one of these; we are merely the type-safe type usable for it.
A default-constructed Thread_token is "none": it equals no thread's token, ever – so a data member of this type needs no explicit not-yet-set sentinel value or initializer.
It converts to id_t implicitly, so comparisons and the like work as for an integer; while the reverse requires a deliberate Thread_token{...} (type-safety being the whole point). ostream<< prints it in fixed-width hex (see that operator's doc header): a token is an identity, not a quantity. Thread_tokens are usable as associate keys, whether ordered or unordered.
Stylistically there is some inconsistency between Unique_id_holder and Thread_token; for example Unique_id_holder::create_unique_id() is a static member that returns raw values alongside a default-ctor that creates a Unique_id_holder – while Thread_token default-ctor returns a sentinel, and free function this_thread_unique_token() returns a Thread_token. The two are slightly related too. The inconsistency is neither criminal nor ideal; and the reason for the inconsistency is that Unique_id_holder was written so long ago; the author (ygoldfel) has developed their style since then. That said Unique_id_holder is fine too; it probably could be simplified a bit, but it works fine. We are not marking a to-do here, as it would create unnecessary breaking-code situations, but this all was worth writing down for posterity.
Definition at line 183 of file uniq_id_holder.hpp.
Short-hand for the underlying integer type.
Definition at line 188 of file uniq_id_holder.hpp.
|
constexpr |
Returns m_val; so comparisons and the like work as for an integer.
Definition at line 212 of file uniq_id_holder.hpp.
|
related |
Hashes the given Thread_token; making it, e.g., boost.unordered-compatible as a key out of the box.
| val | Object to hash. |
Definition at line 107 of file uniq_id_holder.cpp.
|
related |
Prints string representation of the given Thread_token to the given ostream: the low 32 bits of the underlying integer in fixed-width hex – 0x followed by exactly N (as of this writing N=8) zero-padded digits – a token being an identity, not a quantity.
Why the low bits only? Tokens come from a monotonic counter, so the high bits are zeros until the 2^32nd ID is issued process-wide – i.e., in practice always – and would print as pure noise; like an abbreviated git hash, the short form identifies uniquely in all but shocking situations. (The stored value keeps all 64 bits regardless; print Thread_token::id_t(val) for the full value.)
| os | Stream to which to write. |
| val | Object to serialize. |
os. Definition at line 90 of file uniq_id_holder.cpp.
| id_t flow::util::Thread_token::m_val = 0 |
The underlying integer value; 0 <=> "none." Typically it is better to assign to *this rather than to m_val.
Definition at line 193 of file uniq_id_holder.hpp.