算法库(五)

13.       lexicographical_compare:按字典顺序比较

class _functorTest

{

public:

         enumcpm_enum{ normal_cpm,nonormal_cpm };

         _functorTest(cpm_enum param =nonormal_cpm ):_cValue( param ){}

         static bool cpm_fun( const char _left,const char _right )

         {

                   returntoupper( _left ) < toupper( _right );

         }

         bool operator()( conststring _fLeft,const string _fRight )

         {

                   if( _cValue == normal_cpm )

                   {

                            return _fLeft < _fRight;

                   }

                   else

                   {

                            returnlexicographical_compare(_fLeft.begin(),_fLeft.end(),_fRight.begin(),_fRight.end(),cpm_fun);

                   }

 

         }

private:

         constcpm_enum _cValue;

};

 

int main()

{

         _functorTest fun(_functorTest::nonormal_cpm );

         typedef  map<string,string,_functorTest>map_Functor;

         map_Functor _map_owner( fun );

 

         _map_owner.insert(make_pair( "Deutschland","Germany") );

         _map_owner.insert(make_pair( "deutsch","German") );

         _map_owner.insert(make_pair( "Haken","snag") );

         _map_owner.insert(make_pair( "deutschland","enterprise") );

         for (map_Functor::iterator iterPos =_map_owner.begin();iterPos !=_map_owner.end();++ iterPos )

         {

                   cout<<"first :"<<iterPos->first<<second:"<<iterPos->second<<"\n";

         }

 

         system("pause");

         return0;

}

输出结果:

first :deutsch  second:German

first:Deutschland  second:Germany

first :Haken  second:snag

 

你可能感兴趣的:(算法库(五))