Probably, for the same reasons, iterators are almost always passed by value: copying an iterator is considered "cheap." In the case of initializer_list there is also the fact that most instances will be temporary with trivial destructors, so the compiler can build them directly where it places the function argument without copying. Finally, there is the fact that, as iterators, the called function will probably want to change the value, which means that it would have to copy it locally if it were passed in with a reference to const.
EDIT:
Just to summarize: the standard library makes the assumption in general that it is better to pass iterators, initializer_lists, and function objects by value. As a result, you must make sure that any iterators, iterator_lists or function objects that you develop are cheap to copy, and you have to accept in your own code that they are cheap to copy. The traditional rule about when to use const references and when to use a value should probably be changed to reflect this:
Use pass by reference to const for class types other than iterators, initializer_lists, or function objects; otherwise use pass by value.
James Kanze Jul 23 '13 at 8:09 2013-07-23 08:09
source share