diff --git a/doc/is_palindrome.qbk b/doc/is_palindrome.qbk index 928de6f..f37ca07 100644 --- a/doc/is_palindrome.qbk +++ b/doc/is_palindrome.qbk @@ -79,6 +79,8 @@ All of the variants of `is_palindrome` take their parameters by value or const r * If you use version of 'is_palindrome' without custom predicate, 'is_palindrome' uses default 'operator==' for elements. If you want use custom predicate, you must redefine 'operator=='. +* Don't use 'const char*' with 'is_palindrome', because 'const char*' is always non-palindromic ('\0' at the end). If you will try to compile 'is_palindrome' with 'const char*', you will get an error. + [endsect] [/ File is_palindrome.qbk diff --git a/include/boost/algorithm/is_palindrome.hpp b/include/boost/algorithm/is_palindrome.hpp index 61acbae..0080e60 100644 --- a/include/boost/algorithm/is_palindrome.hpp +++ b/include/boost/algorithm/is_palindrome.hpp @@ -102,6 +102,22 @@ bool is_palindrome(const R& range, Predicate p) return is_palindrome(boost::begin(range), boost::end(range), p); } +//Disable is_palindrome for const char* because it work not properly. +//Please use string_view for const char* cases. +//Here we use dirty hack to disable 'is_palindrome' with 'const char*' +//URL: http://stackoverflow.com/questions/14637356/static-assert-fails-compilation-even-though-template-function-is-called-nowhere +template +struct foobar : std::false_type +{ }; + +template +bool is_palindrome(const char* str) +{ + static_assert(foobar::value, "Using 'is_palindrome' for 'const char*' is dangerous, because result is always false" + "(reason: '\0' in the end of the string). You can use string_view in this case"); + return false; +} + }} #endif // BOOST_ALGORITHM_IS_PALINDROME_HPP