std::locale::operator()
Aus cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody> template< class CharT, class Traits, class Alloc > bool operator()( const basic_string<CharT,Traits,Alloc>& s1, const basic_string<CharT,Traits,Alloc>& s2) const; |
||
Vergleicht zwei String-Argumente
s1 und s2 nach den lexikographischen Vergleich Vorschriften dieser Ländereinstellung std::collate<charT> Facette definiert. Dieser Operator ermöglicht jedem Objekt, das einen Schauplatz collate Facette als binäres Vergleichselement in den Standard-Algorithmen (wie std::sort) und geordnet Containern (wie std::set) verwendet werden mussOriginal:
Compares two string arguments
s1 and s2 according to the lexicographic comparison rules defined by this locale's std::collate<charT> facet. This operator allows any locale object that has a collate facet to be used as a binary predicate in the standard algorithms (such as std::sort) and ordered containers (such as std::set)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Parameter
| s1 | - | der erste String zu vergleichen
Original: the first string to compare The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| s2 | - | die zweite Zeichenfolge zu vergleichen
Original: the second string to compare The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Rückgabewert
true wenn s1 lexikographisch weniger als s2, false sonst .Original:
true if s1 is lexicographically less than s2, false otherwise.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Mögliche Implementierung
template<class CharT, class Traits, class Alloc >
bool operator()(const std::basic_string<CharT,Traits,Alloc>& s1,
const std::basic_string<CharT,Traits,Alloc>& s2) const;
{
return std::use_facet<std::collate<GharT>>(*this).compare(
s1.data(), s1.data() + s1.size(),
s2.data(), s2.data() + s2.size() ) < 0;
}
|
Beispiel
Ein Vektor von Strings kann nach einem Nicht-Standard-Locale mit dem Gebietsschema Objekte als Komparator sortiert werden:
Original:
A vector of strings can be sorted according to a non-default locale by using the locale object as comparator:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
#include <locale>
#include <algorithm>
#include <vector>
#include <string>
#include <cassert>
int main()
{
std::vector<std::wstring> v = {L"жил", L"был", L"кот"};
std::sort(v.begin(), v.end(), std::locale("ru_RU.UTF8"));
assert(v[0] == L"был");
assert(v[1] == L"жил");
assert(v[2] == L"кот");
}
Siehe auch
definiert lexikographische Vergleich und Hashing von Strings Original: defines lexicographical comparison and hashing of strings The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Klassen-Template) | |