Home > database >  Why does std::initializer_list lack cbegin/cend/empty etc. methods?
Why does std::initializer_list lack cbegin/cend/empty etc. methods?

Time:10-02

I wonder why std::initializer_list has begin/end methods, but lacks cbegin/cend/empty, etc. methods.

Minimizing std::initializer_list is one possibility, however, what is the point of minimizing it? I think such methods do not just belong to the containers, they are also useful for std::initializer_list.

Why?

CodePudding user response:

I don't know the reason why cbegin() and cend() are not part of std::initializer_list, but was a mistake to add cbegin() and cend() to standard library containers, something that should be spelled std::as_const(x).begin() should not be made into a member function for mere convenience. See http://www.gotw.ca/gotw/084.htm.

Mistakes shouldn't be added to classes that don't have them yet.

  • Related