Assign with nullptr and zero size

If I, for example, have a vector v, is this normal by standard:

void setData(const uint8_t* p, size_t s) {
    v.assign(p, p+s);
}

setData(nullptr, 0);

In general, it is always normal to call STL functions XXX(InputIterator first, InputIterator last), as described above, when distance(first,last) == 0?

+4
source share
2 answers

Yes. It is ok to copy the value nullptrto another pointer object and that the whole implementation could do this. It is already forbidden to go past the end (defined here from the beginning == end) or play it.

+1
source

In addition to what is stated in Potatoswatter, C ++ also made a nullptr + 0 valid statement . This was not the case in C.

+1
source

Source: https://habr.com/ru/post/1527505/


All Articles