palindrome_tester< Char, Traits > Class Template Reference

List of all members.

Public Types

typedef
std::basic_string
< Char, Traits > 
string
 Convenience typedef.

Public Member Functions

 palindrome_tester (std::locale &locale)
bool isalpha (Char c) const
Char lowercase (Char c) const
bool operator() (string const &str) const


Detailed Description

template<class Char, class Traits = std::char_traits<Char>>
class palindrome_tester< Char, Traits >

Class to test for a palindrome. I converted the functions to a class so I could cache the ctype facet.

Definition at line 16 of file palindrome.cpp.


Constructor & Destructor Documentation

template<class Char, class Traits = std::char_traits<Char>>
palindrome_tester< Char, Traits >::palindrome_tester ( std::locale &  locale  )  [inline]

Construct the palindrome tester for the given locale. Cache the locale to use for testing characters.

Parameters:
locale The locale to use for interpreting characters

Definition at line 26 of file palindrome.cpp.


Member Function Documentation

template<class Char, class Traits = std::char_traits<Char>>
bool palindrome_tester< Char, Traits >::isalpha ( Char  c  )  const [inline]

Test for non-letter.

Parameters:
c the character to test
Returns:
true if ch is not a letter

Definition at line 35 of file palindrome.cpp.

Referenced by palindrome_tester< Char, Traits >::operator()().

template<class Char, class Traits = std::char_traits<Char>>
Char palindrome_tester< Char, Traits >::lowercase ( Char  c  )  const [inline]

Convert to lowercase. Use a canonical form by converting to uppercase first, and then to lowercase.

Parameters:
c the character to convert
Returns:
the character converted to lowercase

Definition at line 43 of file palindrome.cpp.

Referenced by palindrome_tester< Char, Traits >::operator()().

template<class Char, class Traits = std::char_traits<Char>>
bool palindrome_tester< Char, Traits >::operator() ( string const &  str  )  const [inline]

Determine whether str is a palindrome. Only letter characters are tested. Spaces and punctuation don't count. Empty strings are not palindromes because that's just too easy.

Parameters:
str the string to test
Returns:
true if str is the same forward and backward

Definition at line 51 of file palindrome.cpp.

References palindrome_tester< Char, Traits >::isalpha(), and palindrome_tester< Char, Traits >::lowercase().


The documentation for this class was generated from the following file:
Generated on Sun Nov 30 09:53:23 2008 for Exploring C++ - Final Forms of Key Examples by  doxygen 1.5.3