Click here to Skip to main content
15,671,882 members
Articles / Programming Languages / C++

Tagged as


3 bookmarked

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
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.


Daily Counts


Weekly Counts


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

Written By
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