Re: Why doesn't push_back return an iterator?
On 2012-07-23 04:15, Kaba wrote:
A small but annoying piece of STL is that the push_back and push_front
member functions of std::list (say) do not return an iterator to the
created element. This results in having to do something like
auto iter = list.end();
--iter;
This is bad; it does not compose, it is redundant, and opens up a door
for possibly getting it wrong.
Why was the iterator-return left off from C++03?
Why was the iterator-return left off from C++11?
I cannot give you a definite answer to these questions, but if you
investigate the history of proposal documents from
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/
you can find
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/1995/N0760.htm
(Search for "Issue Number: 23-002"). So your issue was already raised
in 1995 and the conclusion at that time was:
This issue was discussed by the LWG at the Austin meeting.
The general proposal to add iterator return values to
various container member functions did not generate enough
support to be brought before the full committee. Therefore,
this issue was closed.
However, it was noted that the description of insert() must
specify which iterator value is returned. The intent it to
return an iterator to the element just inserted.
Your questions refer to C++03 and C++11, so in this case I guess that
no-one had enough interest in proposing another time the same thing
possibly providing this time more arguments why the cost of changing the
specification and each and every implementation would be justified by
the obvious advantages.
Nevertheless, the C++ standard is no fixed document and if you have
enough interest for this feature request it is a good time to write up a
proposal and to follow the standardization process carefully. It would
presumably be helpful, if you or you ISO representative would be present
at such a meeting, unless your proposal is so convincing that it becomes
immediately accepted ;-)
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]