template <typename T>
class myvector
{
...
/**
* @brief Returns the number of elements in the container.
* @return The number of elements in the container.
*/
size_type size(void) const noexcept
{
return size_;
}
...
private:
pointer heap_ = nullptr;
size_type size_ = 0;
size_type capacity_ = 0;
};
メンバ変数である size_ を返すだけの関数です。const かつ noexcept となります。
全ソースコード: https://github.com/suomesta/myvector/tree/master/004
0 件のコメント:
コメントを投稿