String :: erase (0) on an empty string?

Is the behavior of std::string::erase(0) correct for an empty string. Because cppreference says:

 Removes count characters starting at index. 

But for an empty string, the character at index 0 does not exist.

+6
source share
2 answers

Everything seems to be in order, as row size 0 :

21.4.6.5 basic_string :: erase [string :: erase]

basic_string<charT,traits,Allocator>& erase(size_type pos = 0, size_type n = npos);

1 Required: pos <= size()

2 Throws: out_of_range if pos > size() .

+9
source

On the same page std::string::erase I found these lines:

Exceptions
1) std :: out_of_range if index > size() .
2-3) (no)

+4
source

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


All Articles