KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Suppose that you are writing a function that accepts an std::initializer_list called list , and that the function requires random access to list 's elements. It would be convenient to write list[i] instead of list.begin()[i] . So why doesn't std::initializer_list provide a definition of operator[] ? I can't think of any cases where an operator[] returning const T& would not be well-defined. Efficiency doesn't seem to be the issue here, since std::initializer_list<T>::iterator is aliased to const T* , which is clearly a random-access iterator.
Tags (comma-separated)
Save Edits
Cancel