
Class template designed to express optionality without having to sacrifice memory to store additional bool flag
The mp::opt<T, Policy> class template is an innovative solution designed for C++ developers looking to express optional values efficiently. Unlike std::optional<T>, this implementation does not require additional storage for a boolean flag to signify whether a value is set, making it a space-efficient alternative. By cleverly utilizing the underlying representation of type T, this template allows developers to define a special value that indicates "emptiness," promoting more meaningful code without the overhead.
This header-only library, which relies on C++14 features, requires a modern compiler and can be easily integrated into existing projects. With its straightforward policy design and customizable options, mp::opt<T, Policy> provides users with the flexibility to tailor the behavior of optional values according to their needs.
Space Efficiency: Utilizes the underlying representation of type T to avoid the need for a boolean flag for value presence, thereby saving memory.
Customizable Policies: Users can define their own policy classes to specify how "emptiness" should be represented, allowing for tailored behavior specific to the type in use.
Built-in Policies: The library comes with default policies, such as mp::opt_default_policy<T>, which can easily be specialized for different types, simplifying usage for common scenarios.
Seamless Integration: As a header-only library, it can be included simply with #include <opt.h>, making it easy to add to ongoing projects without complex installation steps.
Support for Integral Types: The library includes specialized policies such as mp::opt_null_value_policy<T, NullValue>, which enables users to define null values directly in type definitions for better clarity and use in computations.
Robust Comparison Handling: Offers default methods to compare contained values with the null value defined in the policy, ensuring that users can easily implement and maintain equality checks.
Flexibility for Custom Types: By allowing definitions of null values and comparison logic, the library is suitable for user-defined types that may not fit traditional equality paradigms, broadening its application.
Clear Documentation and Examples: The library provides practical usage examples, making it accessible for both new and experienced C++ developers looking to implement optional types.
