Boost logo

Boost :

Subject: Re: [boost] 'is_palindrome' and 'const char*'
From: Зайцев Александр (zamazan4ik_at_[hidden])
Date: 2016-08-14 17:33:14


I agree with your point of view. I will disable const char* version with static_assert.

Thanks for the answer!

14.08.2016, 05:53, "Richard Hodges" <hodges.r_at_[hidden]>:
> My feeling would be that the const char* version should be specifically
> disabled for the following reasons:
>
> 1. it encourages the use of unwrapped c-style strings.
> 2. c++17 will soon be offering string_view, which will already perform as
> intended.
> 3. not all char buffers are null-terminated. expecting the buffer to be so
> can be equally surprising.
> 4. const char* is not a Range, and it is trivial to wrap it so that it
> behaves like one.
>
> If disabled, the ensuing error message could even me a nicely worded string
> (via static_assert) that what the user is about to do is dangerous. An
> alternative can be suggested in the same string. Now the the function has
> become safe and educational.
>
> On 13 August 2016 at 03:33, Rob Stewart <rstewart_at_[hidden]> wrote:
>
>>  On August 11, 2016 9:00:12 PM EDT, "Зайцев Александр" <zamazan4ik_at_[hidden]>
>>  wrote:
>>  > Hello. I have some question about some case for 'is_palindrome' algo.
>>  >
>>  > 'is_palindrome' algorithm checks a sequence - if sequence is a
>>  > palindromeor empty, function returns true, in other cases returns
>>  > false.
>>  >
>>  > But in case e.g. "a" (is_palindrome("a")) result is false, because "a"
>>  > = {'a', '\0'}. And maybe this behaviour is unexpected for users.
>>  >
>>  > So... what do you think about it? Should I implement special version
>>  > for const char* or not?
>>
>>  That certainly seems appropriate to me.
>>
>>  --
>>  Rob
>>
>>  (Sent from my portable computation device.)
>>
>>  _______________________________________________
>>  Unsubscribe & other changes: http://lists.boost.org/
>>  mailman/listinfo.cgi/boost
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

-- 
С уважением, Зайцев Александр.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk