Click here to Skip to main content
15,884,298 members
Articles / Programming Languages / C++

number_cast<To, From> and Named Smart Casts

Rate me:
Please Sign up or sign in to vote.
5.00/5 (7 votes)
6 May 2022CPOL14 min read 4.5K   69   3  
A more descriptive and tightly scoped cast for numeric conversions. Includes rounding options, overflow checks, a high resilience to coding errors and some special syntactical conveniences.
number_cast is strongly typed to specific numerical conversions with options for rounding during conversions, conversion overflow checking and a high resilience to coding errors. It can be used as a generic verbose casting function, in the same manner as static_cast. Or specific commonly used conversions can be aliased to a descriptive name whose correct application has the uncluttered appearance and the syntactical flexibility of a C style cast.

Views

Daily Counts

Downloads

Weekly Counts

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Retired
Spain Spain
Software Author with engineering, science and mathematical background.

Many years using C++ to develop responsive visualisations of fine grained dynamic information largely in the fields of public transport and supply logistics. Currently interested in what can be done to make the use of C++ cleaner, safer, and more comfortable.

Comments and Discussions