std::string provides a max_size() method to determine the maximum number of elements it can contain.
However, to work out the maximum lengt
std::string::max_size() calls std::allocator::max_size() under the hood.
According to the standard, 20.9.6.1.10:
size_type max_size() const noexcept;Returns: The largest value N for which the call allocate(N,0) might succeed.
(See also: allocator::max_size)
Theoretically, an allocator implementation could be able to work out the maximum size of a chunk of memory it could allocate via a syscall. This would help determine the largest possible size for a string, inside a specific process.