Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Gary Daniels and Evan Goldring - Mock whiteboard problem
Mar 25, 2005 at 3:34 PMThis problem is so simple that the whole solution is just one line of generic code (also with guaranteed complexity):
template<typename StringType>
inline bool is_palindrom(const StringType& str)
{
return std::equal(str.begin(), str.begin() + str.size()/2, str.rend());
}
now you can instantiate the function on std::string, std::wstring, std::vector<char>, or whatever container is appropriate for your application, which has random access iterators. And if you need to make it case-insensitive, just add a corresponding binary predicate for std::equal, which is another one line of code for English, or can be non-trivial for other languages. You can even test for palindrom objects that are not strings, as long as they contain equality comparable types.