为什么没有std :: size?

时间:2015-02-13 11:27:09

标签: c++ stl c++14

Scott MeyersHerb Sutterothers提倡非会员职能而不是会员职能。并且通过std::beginstd::cend等附加功能,似乎STL正朝着这个方向发展。如果是这种情况,为什么没有std::size

我认为,因为它很容易定义您自己的版本:

namespace std {
    // C++14
    template <typename C>
    decltype(auto) size(const C& c)
    {
        return distance(cbegin(c), cend(c));
    }
}

或者我错过了什么?即是否有理由使用非成员size

1 个答案:

答案 0 :(得分:6)

  

为什么没有std::size

因为没有人及时写出提案,因为它被包含在C ++ 14中。 The first draft of the proposal to add it发布于2014年5月,是在C ++ 14标准于2014年2月进行最后一轮投票后发布的。

该提案的A revised versionvoted into the C++ working paper,是委员会11月份的最后一次会议(见LWG动议20),所以您很可能会看到它在标准的下一版本(C ++ 17?)中,以及std::empty()std::data()

相关问题