...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
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 overloads: 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 addresses about 40% of all use cases. If this is insufficient, you need to resort to using In-Place Factories.