|
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