lmi
[Top][All Lists]
Advanced

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

[lmi] Cating doubles to enums


From: Vadim Zeitlin
Subject: [lmi] Cating doubles to enums
Date: Fri, 2 Nov 2018 16:20:08 +0100

 Hello,

 Building the latest sources with MSVS 2017 results in

input_harmonization.cpp(101): error C2440: 'static_cast': cannot convert from 
'double' to 'mcenum_ledger_type'
input_harmonization.cpp(101): note: Conversions between enumeration and 
floating point values are no longer allowed

and many other similar errors in the same file as well as in gpt_input.cpp,
ihs_acctval.cpp, ihs_basicval.cpp, ledger_invariant_init.cpp and
mec_input.cpp.

 Somewhat to my surprise, I confirmed that casting floating point values to
(complete) enum values is indeed valid in C++ but nevertheless MSVS seems
to intentionally disallow this.

 This is, of course, a big problem for me, so I'd like to fix it in some
way. I can make MSVS-specific changes on my local branch, of course, but
this is going to be rather painful considering the number of such casts and
the fact that they will probably keep changing in the future.

 So I wonder if you would consider adding some kind of enum_cast<> function
which would cast a double to int first using bourn_cast<> and then,
possibly after checking the validity of the int as an enum element, cast it
to the target type using static_cast<>? This would solve my problem, which
is the immediate reason for proposing it, but would also IMO be slightly
more readable and potentially safer. Of course, I could provide a patch
doing this if you agree with this change in principle.

 What do you think?
VZ


reply via email to

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