Why does constructor (4) exist for std::variant
from http://en.cppreference.com/w/cpp/utility/variant/variant? It seems like it is going to cause a lot of ambiguity in code that could otherwise have been avoided by being explicit.. For example the code sample on cppreference highlights a possible ambiguity that users might not notice (the third line)
variant<string> v("abc"); // OK
variant<string, string> w("abc"); // ill-formed, can't select the alternative to convert to
variant<string, bool> w("abc"); // OK, but chooses bool
Is there some case where it is absolutely going to be needed?
The other question was why constructors (6) and (8) are needed from the same cppreference page. Won't (5) and (7) serve the purposes that (6) and (8) are meant for? I might be misunderstanding their usage..
For the reader the constructors that I referred to in my question are
constexpr variant(); // (1) (since C++17)
variant(const variant& other); // (2) (since C++17)
variant(variant&& other); // (3) (since C++17)
template< class T > // (4) (since C++17)
constexpr variant(T&& t);
template< class T, class... Args >
constexpr explicit variant(std::in_place_type_t<T>, Args&&... args); // (5) (since C++17)
template< class T, class U, class... Args >
constexpr explicit variant(std::in_place_type_t<T>,
std::initializer_list<U> il, Args&&... args); // (6) (since C++17)
template< std::size_t I, class... Args >
constexpr explicit variant(std::in_place_index_t<I>, Args&&... args) // (7) (since C++17)
template <size_t I, class U, class... Args>
constexpr explicit variant(std::in_place_index_t<I>,
std::initializer_list<U> il, Args&&... args); // (8) (since C++17)
in_place<T>
constructor every time you initialize a variant with one of the bounded types? – Adams