Both arithmetic (built-in) and user-defined numeric types require proper
(that is, with (in-class) integral constants).
The library uses
std::numeric_limits<T>::is_specialized to detect whether the type
is builtin or user defined, and
std::numeric_limits<T>::is_signed to detect whether the type is
integer or floating point; and whether it is signed/unsigned.
policies uses unqualified calls to functions
ceil(); but the standard functions are introduced
in scope by a using directive:
using std::floor ; return floor(s);
Therefore, for builtin arithmetic types, the std functions will be used. User defined types should provide overloaded versions of these functions in order to use the default rounder policies. If these overloads are defined within a user namespace argument dependent lookup (ADL) should find them, but if your compiler has a weak ADL you might need to put these functions some place else or write your own rounder policy.
rounder policy needs to determine if the source value is positive or not,
and for this it evaluates the expression
< static_cast<S>(0). Therefore,
user defined types require a visible
operator< in order to use the
Trunc<> policy (the default).
If a User Defined Type is involved in a conversion, it is assumed
that the UDT has wider
range than any built-in type, and consequently the values of some
members are hardwired regardless of the reality. The following table summarizes
udt_mixture can be used to detect whether
a UDT is involved and to infer the validity of the other members as shown
Because User Defined Numeric Types might have peculiar ranges (such as an
unbounded range), this library does not attempt to supply a meaningful range
checking logic when UDTs are involved in a conversion. Therefore, if either
Target or Source are not built-in types, the bundled range checking of the
function object is automatically disabled. However, it is possible to supply
a user-defined range-checker. See Special
There are two components of the
converter<> class that might require special
behavior if User Defined Numeric Types are involved: the Range Checking and
the Raw Conversion.
When both Target and Source are built-in types, the converter class uses an internal range checking logic which is optimized and customized for the combined properties of the types.
However, this internal logic is disabled when either type is User Defined. In this case, the user can specify an external range checking policy which will be used in place of the internal code. See UserRangeChecker policy for details.
The converter class performs the actual conversion using a Raw Converter
policy. The default raw converter simply performs a
However, if the a UDT is involved, the
might not work. In this case, the user can implement and pass a different
raw converter policy. See RawConverter
policy for details