Re: initializer lists
On 3/22/2014 6:51 AM, Luca Risolia wrote:
Victor Bazarov wrote:
It's
quite possible that 'std::initializer_list<T>' is convertible to
'std::initializer_list<U>' if 'T' is convertible to 'U'. Too lazy to
dig in the Standard for a confirmation.
std::cout << std::is_convertible<std::initializer_list<int>,
std::initializer_list<char>>::value; // 0
Ok, thanks for that.
I looked in the Standard, and it defines a constructor for
'basic_string' class template from 'std::initializer_list<charT>', not
from 'std::initalizer_list<int>'. So, to me it's obvious that the
compiler should try to interpret the {65, 'A'} notation as the
initializer list of char, not of int, and from that it will initialize
the string object (as if from a pair of iterators).
Now, again due to laziness I haven't found a confirmation for that in
the Standard. What allows the compiler to interpret that initializer
list as initializer_list<char> instead of <int>, I am not sure, but
apparently something does :-)
V
--
I do not respond to top-posted replies, please don't ask