std::collat...o_transform(3)
πΈ std::collate::transform,do_transform πΈ
okay bestie, welcome to the std::collat...o_transform(3) page from the C++ Standard Libary manual. Yes, that spelling is what the header says, and we're keeping it. This whole page is about transform-and-compare energy in <locale> β no cap, every detail is staying. π
π NAME π
std::collate::transform,do_transform β literally the NAME line says std::collate::transform,do_transform - std::collate::transform,do_transform. It's giving "say it twice and make it make sense." π
β¨ Synopsis β¨
Defined in header <locale>. Here's the signature setup exactly as written:
Defined in header <locale>
public:
(1)
string_type transform( const CharT* low, const CharT* high ) const;
protected:
(2)
virtual string_type do_transform( const CharT* low, const CharT* high
) const;
(1)β public member function, calls the protected virtual member functiondo_transformof the most derived class.(2)β converts the character sequence[low, high)to a string that, compared lexicographically (e.g. withoperator<for strings) with the result of callingtransform()on another string, produces the same result as callingdo_compare()on the same two strings.
π Parameters π
lowβ pointer to the first character in the sequence to transform.highβ one past the end pointer for the sequence to transform.
π Return value π
The string transformed so that lexicographic comparison of the transformed strings may be used instead of collating the originals. In the "C" locale, the returned string is the exact copy of [low, high). In other locales, the contents of the returned string are implementation-defined, and the size may be considerably longer. π«Ά
π§ Notes π§
In addition to the use in collation, the implementation-specific format of the transformed string is known to std::regex_traits<>::transform_primary, which is able to extract the equivalence class information. That's the little behind-the-scenes cameo. β¨
π₯ Example π₯
Time for the demo. Here's the code, verbatim:
// Run this code
#include <iomanip>
#include <iostream>
#include <locale>
int main()
{
std::locale::global(std::locale("sv_SE.utf8"));
auto& f = std::use_facet<std::collate<wchar_t>>(std::locale());
std::wstring in1 = L"\u00e4ngel";
std::wstring in2 = L"\u00e5r";
std::wstring out1 = f.transform(&in1[0], &in1[0] + in1.size());
std::wstring out2 = f.transform(&in2[0], &in2[0] + in2.size());
std::wcout << "In the Swedish locale: ";
if (out1 < out2)
std::wcout << in1 << " before " << in2 << '\n';
else
std::wcout << in2 << " before " << in1 << '\n';
std::wcout << "In lexicographic comparison: ";
if (in1 < in2)
std::wcout << in1 << " before " << in2 << '\n';
else
std::wcout << in2 << " before " << in1 << '\n';
}
π Output: π
In the Swedish locale: Γ₯r before Γ€ngel
In lexicographic comparison: Γ€ngel before Γ₯r
π See also π
strxfrmβ transform a string so thatstrcmpwould produce the same result asstrcoll(function).wcsxfrmβ transform a wide string so thatwcscmpwould produce the same result aswcscoll(function).
source: http://cppreference.com Β· version/date: 2024.06.10 Β· manual: std::collat...o_transform(3) β byeee bestie, go transform something iconic π
β¨
π¦ 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