Thanks.
I only tested with the fixed (portable) code, using <math.h> instead of
<cmath>. With that, argument `4.` worked with both g++ and Visual C++.
Using <math.h> should ideally not have made any difference: either it
should compile or not, I thought.
But as it turns out, when you include <math.h>, or include <cmath> with
a `using std::pow`, with g++ you get an additional overload
template< class _Tp, class _Up >
auto pow( _Tp, _Up )
-> constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type;
and with Visual C++ there is anyway an overload
auto pow( double, int ) -> double;
I found these overloads simply by compiling a call `pow( "Blah", 2 )`.
In C++17 the wording that mandates such overloads, without detailing
exactly what they should be, is §2.9.1/2:
<quote>
For each set of overloaded functions within <cmath> , with the exception
of `abs`, there shall be additional overloads sufficient to ensure:
1. If any argument of arithmetic type corresponding to a double
parameter has type long double , then all arguments of arithmetic type
(6.9.1) corresponding to double parameters are effectively cast to long
double.
2. Otherwise, if any argument of arithmetic type corresponding to a
double parameter has type double or an integer type, then all arguments
of arithmetic type corresponding to double parameters are effectively
cast to double.
3. Otherwise, all arguments of arithmetic type corresponding to double
parameters have type float.
[Note: `abs` is exempted from these rules in order to stay compatible
with C. —end note ]
</quote>
So that's the technical: when `<math.h>` is included, or alternatively
when one includes `<cmath>` with a `using std::pow;` or `using namespace
std;`, then the expression `pow( 4., 7 )` is well-defined, unambiguous.
However, I hadn't thought this through. I could just as well have turned
out wrong. So, thanks, that was a learning experience. :)
Cheers!,
- Alf