# std::basic_string_view<CharT,Traits>::max_size

> C++ Atlas: `cppatlas.com/w/cpp/string/basic_string_view/max_size` | Source: https://en.cppreference.com/w/cpp/string/basic_string_view/max_size | Domain: Strings | Standards: C++17

The largest possible number of char-like objects that can be referred to by a basic_string_view.

## Official Specification Summary (cppreference)

```cpp
constexpr size_type max_size() const noexcept; // (since C++17)
```

The largest possible number of char-like objects that can be referred to by a `basic_string_view`.

### Parameters

(none)

### Return value

Maximum number of characters.

### Complexity

Constant.

### Example

```cpp
#include <cstdint>
#include <iostream>
#include <limits>
#include <string_view>

int main()
{
    std::cout << std::numeric_limits<std::int64_t>::max()
              << " <- numeric_limits<int64_t>::max()\n"
              << std::string_view{}.max_size()
              << " <- string_view::max_size()\n"
              << std::basic_string_view<char>{}.max_size()
              << " <- basic_string_view<char>::max_size()\n"
              << std::basic_string_view<char16_t>{}.max_size()
              << " <- basic_string_view<char16_t>::max_size()\n"
              << std::wstring_view{}.max_size()
              << " <- wstring_view::max_size()\n"
              << std::basic_string_view<char32_t>{}.max_size()
              << " <- basic_string_view<char32_t>::max_size()\n";
}
```

Possible output:

```text
9223372036854775807 <- numeric_limits<int64_t>::max()
4611686018427387899 <- string_view::max_size()
4611686018427387899 <- basic_string_view<char>::max_size()
2305843009213693949 <- basic_string_view<char16_t>::max_size()
1152921504606846974 <- wstring_view::max_size()
1152921504606846974 <- basic_string_view<char32_t>::max_size()
```

### See also

- [`size`](https://en.cppreference.com/w/cpp/string/basic_string_view/size), [`length`](https://en.cppreference.com/w/cpp/string/basic_string_view/size): returns the number of characters (public member function)
- [`empty`](https://en.cppreference.com/w/cpp/string/basic_string_view/empty): checks whether the view is empty (public member function)
- [`max_size`](https://en.cppreference.com/w/cpp/string/basic_string/max_size): returns the maximum number of characters (public member function of `std::basic_string<CharT,Traits,Allocator>`)

---
Attribution: content from https://en.cppreference.com/w/cpp/string/basic_string_view/max_size (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.