I would like to know if the difference of "2 concrete nullptr" of the same type is guaranteed to be equal to 0. I can't find anything in the C++ standard that guarantees that.
template <typename T>
std::ptrdiff_t diff() {
T* p = nullptr;
T* q = nullptr;
return p - q;
}
In other words, does this code "has" to return 0?
The reason I am asking this question is that I want to implement my own vector class with
template <typename T>
class Vector {
private:
T* data_;
T* size_;
public:
int size() const {
return static_cast<int>(size_ - data_);
}
}
and I am wondering if it is allowed to put data_ = size_ = nullptr when I construct a vector of length 0.
Aucun commentaire:
Enregistrer un commentaire