#include <locale>
#include <iostream>
using namespace std;
/// collate<char> colc;
template < typename C>
class My_collate : public collate< C>
{
public :
explicit My_collate( size_t r = 0 ) :
collate< C> { r}
{
}
} ;
My_collate< char > mcolc;
void print( const string& s1, const string& s2,
const int & rslt)
{
string srslt { } ;
switch ( rslt)
{
case 0 :
srslt = "equal" ;
break ;
case 1 :
srslt = "s1 > s2" ;
break ;
case - 1 :
srslt = "s1 < s2" ;
break ;
}
cout << "comparison of " << s1 << " and " << s2
<< " using the mcolc facet : "
<< srslt << endl;
}
void test( const string& s1, const string& s2)
{
/// since compare() operates on char[]s
const char * s1b = s1.data ( ) ; /// start of data
const char * s1e = s1b + s1.size ( ) ; /// end of data
const char * s2b = s2.data ( ) ; /// start of data
const char * s2e = s2b + s2.size ( ) ; /// end of data
int rslt = mcolc.compare ( s1b, s1e, s2b, s2e) ;
/// display results
print( s1, s2, rslt) ;
}
int main( )
{
test( "Hello" , "Hello" ) ;
test( "Hello" , "hello" ) ;
test( "hello" , "Hello" ) ;
}
I2luY2x1ZGUgPGxvY2FsZT4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgovLy8gY29sbGF0ZTxjaGFyPiBjb2xjOwoKCnRlbXBsYXRlPHR5cGVuYW1lIEM+CmNsYXNzIE15X2NvbGxhdGUgOiBwdWJsaWMgY29sbGF0ZTxDPgp7CnB1YmxpYzoKICAgIGV4cGxpY2l0IE15X2NvbGxhdGUoc2l6ZV90IHIgPSAwKSA6CiAgICAgICAgY29sbGF0ZTxDPiB7cn0KICAgIHsKICAgIH0KfTsKCk15X2NvbGxhdGU8Y2hhcj4gbWNvbGM7CgoKdm9pZCBwcmludChjb25zdCBzdHJpbmcmIHMxLCBjb25zdCBzdHJpbmcmIHMyLAogICAgICAgICAgIGNvbnN0IGludCYgcnNsdCkKewogICAgc3RyaW5nIHNyc2x0IHt9OwoKICAgIHN3aXRjaChyc2x0KQogICAgewogICAgY2FzZSAwOgogICA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