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?
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With