純粋に heap_ を返します。myvector では heap_ の指し先が nullptr である場合がありますが、data() ではそのことはケアしません。
template <typename T>
class myvector
{
...
/**
* @brief Returns pointer to the underlying array serving as element storage.
* The pointer is such that range [data(), data() + size()) is always
* a valid range, even if the container is empty (data() is not dereferenceable
* in that case).
* @return Pointer to the underlying element storage. For non-empty containers,
* the returned pointer compares equal to the address of the first element.
*/
pointer data(void) noexcept
{
return heap_;
}
/**
* @brief Returns pointer to the underlying array serving as element storage.
* The pointer is such that range [data(), data() + size()) is always
* a valid range, even if the container is empty (data() is not dereferenceable
* in that case).
* @return Const pointer to the underlying element storage. For non-empty containers,
* the returned pointer compares equal to the address of the first element.
*/
const_pointer data(void) const noexcept
{
return heap_;
}
...
};
data() はそれぞれ2種類ありますが、違いは const関数であるか、非const関数であるか、のみです。
全ソースコード: https://github.com/suomesta/myvector/tree/master/022
0 件のコメント:
コメントを投稿