lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Request for code review


From: Greg Chicares
Subject: Re: [lmi] Request for code review
Date: Mon, 23 Jan 2017 22:30:48 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0

On 2017-01-23 21:12, Vadim Zeitlin wrote:
> On Mon, 23 Jan 2017 20:11:00 +0000 Greg Chicares <address@hidden> wrote:
> 
> GC> Two (tested) changes here. The "auto" change seems obvious.
> 
>  Yes, except that I'd use "auto const" but I am, of course, have somewhat
> of an obsession with const local variables...
> 
> GC> The other is Meyers's "Avoid Duplication in const and Non-const Member
> GC> Function" technique. It's already used elsewhere in this file, and I
> GC> kind of like it.
> 
>  I can't say I like it but I definitely dislike it less than duplicating
> code and personally I think it's as good an idea as it ever was. But why
> use static_cast<> instead of (strictly less powerful and hence less
> dangerous, without mentioning that it's also much clearer) const_cast<>?

Meyers says: "The cast that adds const is just forcing a safe conversion
(from a non-const object to a const one), so we use a static_cast for
that." I thought he might have had some profound reason, but I guess he
might be avoiding const_cast because some people think of it as a code
smell, or perhaps he liked to reserve const_cast for removing constness.
Whatever his reason, I find your arguments persuasive. And of course if
we wait until 2017 we can use std::as_const(). C++2017, that is.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]