Advertisement
IonutCava

Compare with switch

Dec 15th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. struct StringComparator
  2. {
  3.     StringComparator(bool ascending) : m_ascending(ascending)
  4.     {
  5.     }
  6.    
  7.     bool operator()(const char* first, const char* second) const
  8.     {
  9.         int result = StringUtility::compareNoCase(first, second);
  10.         return m_ascending ? result <= 0 : result > 0;
  11.     }
  12.    
  13.     bool m_ascending;
  14. };
  15.  
  16. m_values.sort(StringComparator(true)); //ascending
  17. m_values.sort(StringComparator(false)); //descending
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement