Opened 5 years ago

#13208 new Feature Requests

Make boost::optional<T> trivially destructible, copyable and movable if T is

Reported by: 1zeeky@… Owned by: Fernando Cacciola
Milestone: To Be Determined Component: optional
Version: Severity: Not Applicable
Keywords: Cc:

Description

Conceptually there's nothing preventing boost::optional<T> from being trivially destructible, copyable and movable if T is. This could be useful, for instance, to use an boost::optional<T> as a union-member.

I have a POC implementation based on Boost 1.64 here.
I moved m_storage and m_initialized to a new class optional_storage, representing the new base class. Some methods managing those members are move there as well. optional_base indirectly inherits from optional_storage through optional_destroyer, optional_mover and optional_copier, which are templated classes including a boolean parameter to determine whether T is trivially destructible, movable and copyable and use template specialization to provide the respective trivial members.
The implementation relies on defaulting constructors, so without C++11 or newer only trivial destruction is possible.

Change History (0)

Note: See TracTickets for help on using tickets.