|
Boost : |
Subject: [boost] compact_optional -- prompting interest
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2015-09-25 10:35:53
Hi Everyone,
I would like to inquire if there would be an interest in Boost in another
library for storing optional objects, but working under different design
goals.
Compact optional T has (or can have) the same sizeof as T. It uses one
indicated value of T to represent the "empty" (or "singular") value. You
can declare it like this:
compact_optional<evp_int<int, -1>> oi;
This reads: we have an optional int, with type int inside, where -1
represents the empty value. It can never have a genuine (non-empty value
-1). This can be used, for instance, to wrap the std::string::npos into:
compact_optional<evp_int<string::size_type, string::npos>>
With the same memory layout as std::string::size_type, but with the special
syntax for managing the singular value.
It is not meant to be an alternative to Boost.Optional: it targets a
different application space.
The (single-header) implementation is at:
https://github.com/akrzemi1/compact_optional
The documentation is at:
https://github.com/akrzemi1/compact_optional/blob/master/documentation.md
For the motivation and design rationale see this article:
https://akrzemi1.wordpress.com/2015/07/15/efficient-optional-values/
Any feedback is welcome.
Regards,
&rzej
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk