std::locale::operator()
Da cppreference.com.
|
|
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
<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; |
||
Confronta due argomenti di tipo stringa
s1 s2 e secondo le regole di confronto lessicografiche definite da facet std::collate<charT> questo locale è. Questo operatore permette qualsiasi oggetto locale che ha una faccia di fascicolazione per essere usato come un predicato binario in algoritmi standard (come std::sort) e contenitori ordinate (come std::set)Original:
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.
Parametri
| s1 | - | la prima stringa da confrontare
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 | - | la seconda stringa da confrontare
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. |
Valore di ritorno
true se s1 è lessicograficamente minore s2, false altrimenti.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.
Possibile implementazione
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;
}
|
Esempio
Un vettore di stringhe possono essere ordinati in base a una posizione non predefinita locale utilizzando l'oggetto locale come comparatore:
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"кот");
}
Vedi anche
definisce il confronto lessicografico e hashing delle stringhe 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. (classe template) | |