...one of the most highly
regarded and expertly designed C++ library projects in the
world. — Herb Sutter and Andrei
numberto a template function?
Most likely you are actually passing an expression template type to the function and template-argument-deduction deduces the "wrong" type. Try casting the arguments involving expressions to the actual number type, or as a last resort turning off expression template support in the number type you are using.
As a general rule, expression template support adds a small runtime overhead creating and unpacking the expression templates, but greatly reduces the number of temporaries created. So it's most effective in improving performance when the cost of creating a temporary is high: for example when creating a temporary involves a memory allocation. It is least effective (and may even be a dis-optimisation) when temporaries are cheap: for example if the number type is basically a thin wrapper around a native arithmetic type. In addition, since the library makes extensive use of thin inline wrapper functions, turning on compiler optimization is essential to achieving high performance.
Yes they do, sometimes quite radically so, if this is a concern then they should be turned off for the number type you are using.
Some conversions are explicit, that includes construction from a string, or constructing from any type that may result in loss of precision (for example constructing an integer type from a float).
Bitwise operations on negative values (or indeed any signed integer
type) are unspecified by the standard. As a result any attempt to carry
out a bitwise operation on a negative checked-integer will result in
std::range_error being thrown.
Use of the complement operator on signed types is problematic as the
result is unspecified by the standard, and is further complicated by
the fact that most extended precision integer types use a sign-magnitude
representation rather than the 2's complement one favored by most native
integer types. As a result the complement operator is deliberately
disabled for checked
give the same valued result as a 2's complement type would, but not
the same bit-pattern.
The unary negation operator is deliberately disabled for unsigned integer types as its use would almost always be a programming error.
A very early version of the library did use proto, but compile times became too slow for the library to be usable. Since the library only required a tiny fraction of what proto has to offer anyway, a lightweight expression template mechanism was used instead. Compile times are still too slow...
This was deemed not to be practical: these algorithms are intimately tied to the actual data representation used.