mirror of
https://github.com/boostorg/optional.git
synced 2025-07-30 04:27:19 +02:00
documented in-place constructors
This commit is contained in:
@ -27,6 +27,41 @@ The implementation uses the following other Boost modules:
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Emplace operations in older compilers][#optional_emplace_workaround]
|
||||
|
||||
Certain constructors and functions in the interface of `optional` perform a 'perfect forwarding' of arguments:
|
||||
|
||||
template<class... Args> optional(in_place_init_t, Args&&... args);
|
||||
template<class... Args> optional(in_place_init_if_t, bool condition, Args&&... args);
|
||||
template<class... Args> void emplace(Args&&... args);
|
||||
|
||||
On compilers that do not support variadic templates, each of these functions is substituted with two overloads, one forwarding a single argument, the other forwarding zero arguments. This forms the following set:
|
||||
|
||||
template<class Arg> optional(in_place_init_t, Arg&& arg);
|
||||
optional(in_place_init_t);
|
||||
|
||||
template<class Arg> optional(in_place_init_if_t, bool condition, Arg&& arg);
|
||||
optional(in_place_init_if_t, bool condition);
|
||||
|
||||
template<class Arg> void emplace(Arg&& arg);
|
||||
void emplace();
|
||||
|
||||
On compilers that do not support rvalue references, each of these functions is substituted with three overloadss: taking `const` and non-`const` lvalue reference, and third forwarding zero arguments. This forms the following set:
|
||||
|
||||
template<class Arg> optional(in_place_init_t, const Arg& arg);
|
||||
template<class Arg> optional(in_place_init_t, Arg& arg);
|
||||
optional(in_place_init_t);
|
||||
|
||||
template<class Arg> optional(in_place_init_if_t, bool condition, const Arg& arg);
|
||||
template<class Arg> optional(in_place_init_if_t, bool condition, Arg& arg);
|
||||
optional(in_place_init_if_t, bool condition);
|
||||
|
||||
template<class Arg> void emplace(const Arg& arg);
|
||||
template<class Arg> void emplace(Arg& arg);
|
||||
void emplace();
|
||||
|
||||
This workaround addressess about 40% of all use cases. If this is insufficient, you need to resort to using [link boost_optional.tutorial.in_place_factories In-Place Factories].
|
||||
[endsect]
|
||||
|
||||
[section Optional Reference Binding][#optional_reference_binding]
|
||||
|
||||
|
Reference in New Issue
Block a user