std::codecv..._max_length(3)
π std::codecvt::max_length + do_max_length π
Okay so hi bestie!! π This page lives in the C++ Standard Libary manual β yes, that spelling is exactly what the header says, we're keeping it β and the page name is std::codecv..._max_length(3). It's giving βtiny max-length function, main character energy,β so let's go. π¦
πΈ NAME πΈ
std::codecvt::max_length,do_max_length β std::codecvt::max_length,do_max_length. Yep, the NAME line repeats itself and we are not erasing the duplicate, bestie. π
π οΈ Synopsis π οΈ
Defined in header <locale>:
public: (until C++11)
int max_length() const throw();
public: (since C++11)
int max_length() const noexcept; (1)
protected:
(until C++11)
virtual int do_max_length() const throw(); (2)
protected:
(since C++11)
virtual int do_max_length() const noexcept;
- Public member function β it calls the member function
do_max_lengthof the most derived class. - Returns the maximum value that
do_length(state, from, from_end, 1)can return for any valid range[from, from_end)and any validstate.
π Return value π
The maximum number of ExternT characters that could be consumed if converted by in() to produce one InternT character. π«Ά
The non-converting specialization std::codecvt<char, char, std::mbstate_t> returns 1. Slay. β¨
π§ Notes π§
If the encoding is state-dependent (encoding() == -1), then more than max_length() external characters may be consumed to produce one internal character. Heads up, bestie: that's the state-dependent plot twist. π«
π¬ Example π¬
The example literally starts with // Run this code, so go off: π»
#include <codecvt>
#include <iostream>
#include <locale>
int main()
{
std::cout << "In codecvt_utf8, the longest multibyte character is "
<< std::codecvt_utf8<wchar_t>().max_length() << " bytes long\n";
std::cout << "In header-consuming codecvt_utf8, the longest multibyte character is "
<< std::codecvt_utf8<wchar_t,
0x10ffff,
std::consume_header>().max_length()
<< " bytes long\n";
std::cout << "In this system's en_US.utf8, the longest multibyte character is "
<< std::use_facet<std::codecvt<wchar_t, char,
std::mbstate_t>>(
std::locale("en_US.utf8")
).max_length() << " bytes long\n";
std::cout << "In this system's zh_CN.gb18030, the longest multibyte character is "
<< std::use_facet<std::codecvt<wchar_t, char,
std::mbstate_t>>(
std::locale("zh_CN.gb18030")
).max_length() << " bytes long\n";
}
π» Output: π»
In codecvt_utf8, the longest multibyte character is 4 bytes long
In header-consuming codecvt_utf8, the longest multibyte character is 7 bytes long
In this system's en_US.utf8, the longest multibyte character is 6 bytes long
In this system's zh_CN.gb18030, the longest multibyte character is 4 bytes long
π See also π
MB_CUR_MAXβ maximum number of bytes in a multibyte character in the current C locale (macro variable). πdo_encodingβ[virtual]returns the number ofExternTcharacters necessary to produce oneInternTcharacter, if constant (virtual protected member function). π§
Byeeee bestie!! π This page's source/version is http://cppreference.com, its date is 2024.06.10, and it's the std::codecv..._max_length(3) page. Periodt. π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms