Insertion to std::list<std::vector<int>> failed when using initializer list as the value?
Overload resolution for the
lv.insert(lv.end(), {}); // Oops!
call will resolve (formally, chosen as the best viable function as per [over.ics.rank]/3.1) to the following std::list<>::insert
overload [extract from std::list<>::insert
at cppreference, emphasis mine]:
iterator insert( const_iterator pos, std::initializer_list<T> ilist );
inserts elements from initializer list ilist before pos.
But as the initializer list is empty, there are no elements from it to be inserted.
You could likewise invoke the same insert
overload with a nested list initialization within the list initialization,
lv.insert(lv.end(), {{}}); // Size is now 2.
such that the innermost list initialization will resolve to (as per [over.match.list]/1) the std::initializer_list
constructor of std::vector
:
vector( std::initializer_list<T> init, const Allocator& alloc = Allocator() );
in so inserting a single element of type std::vector<int>
, specifically an an empty such vector, into the std::list<std::vector<int>>
object.