Reputation: 8441
Scott Meyers, Herb Sutter and others are advocating non-member functions over member functions. And with additions such as std::begin
, std::cend
, etc, it seems the STL is moving in that direction. If that is the case, why is there no std::size
?
I assume because it's easy enough to define your own version:
namespace std {
// C++14
template <typename C>
decltype(auto) size(const C& c)
{
return distance(cbegin(c), cend(c));
}
}
Or am I missing something? i.e. is there a reason not to use a non-member size
?
Upvotes: 3
Views: 1733
Reputation: 137330
Why is there no
std::size
?
Because nobody wrote a proposal in time for it to be included in C++14. The first draft of the proposal to add it was dated May 2014, well after the C++14 standard was sent out for its last round of ballot in February 2014.
A revised version of the proposal was voted into the C++ working paper at the Committee's last meeting in November (see LWG motion 20), so it's likely that you'll see it in the next revision of the standard (C++17?), along with std::empty()
and std::data()
.
Upvotes: 6