lmi
[Top][All Lists]
Advanced

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

Re: [lmi] Pagination anomaly


From: Greg Chicares
Subject: Re: [lmi] Pagination anomaly
Date: Thu, 8 Feb 2018 13:43:35 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2

On 2018-02-06 21:36, Vadim Zeitlin wrote:
> On Tue, 6 Feb 2018 20:25:54 +0000 Greg Chicares <address@hidden> wrote:
[...]
> GC>         // The cast is only used to ensure that if any new elements are 
> added
> GC>         // to the enum, the compiler would warn about their values not 
> being
> GC>         // present in this switch.
> GC>         switch(static_cast<enum_group_quote_columns>(col))
> GC> 
> GC> wouldn't it be better if 'col' were of type 'enum_group_quote_columns'?
> 
>  I'm not sure if it's really better. It saves the cast here, but it
> requires doing something ugly when incrementing it.

The idea is not to avoid a cast here, but rather to help C++'s strong typing
prevent errors in places that aren't currently under our microscope.

> GC> [...] to iterate across all enumerators
> GC> [...] is defining an array that includes each
> GC> enumerative value, and using ranged for, still the least awful way of
> GC> doing this?
> 
>  AFAIK, yes. And this one at least has the advantage of working with scoped
> C++11 enums as well, unlike the solution with the cast to int for
> increment.

And it would work better with enums that don't use a default value for every
enumerator. But now I see that it would be too ugly, so I won't try it.

But this discussion did give me the useful idea of checking whether switch
statements I'd like to improve actually switch on an enum type. I'm writing
something like
    static_assert(std::is_enum<decltype(ledger_type_)>::value); // ??
or if necessary
    
static_assert(std::is_enum<std::remove_reference_t<decltype(a_StrategyVector[Year])>>::value);
 // ??
right before each one to guard against surprises, with
    #include <type_traits> // ??
in the everywhere-included "config.hpp", with forbidden plain "??" markers
to make sure I remove this scaffolding before committing anything.

That exercise revealed that I had been passing one function's enum arguments
by const reference. I didn't test whether that inhibited '-Wswitch' from
checking that every enumerator has a 'case': whether it does or not, any
such '&' should be removed.



reply via email to

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