Templates and function parametes
Rikki Cattermole via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Aug 9 00:07:37 PDT 2014
On 9/08/2014 6:19 p.m., Paul D Anderson wrote:
> When I try to compile these two functions, the second function is
> flagged with an already defined error:
>
> bool testRoundTrip(T, U)(T first, U second) if (isIntegral!T &&
> isFloatingPoint!U)
> {
> return false;
> }
> bool testRoundTrip(U, T)(U first, T second) if (isIntegral!T &&
> isFloatingPoint!U)
> {
> return false;
> }
>
> They look to me to be distinct functions, one with an integral parameter
> followed by a floating point parameter and the other with a floating
> point parameter followed by an integral parameter.
>
> At first I thought this was a template problem, but the following code
> also raises the same error.
>
> bool testRoundTrip(int first, double second)
> {
> return false;
> }
> bool testRoundTrip(double first, int second)
> {
> return false;
> }
>
> What's the problem?
Cannot reproduce on either 2.065 or git head (according to dpaste).
import std.traits;
bool testRoundTrip(T, U)(T first, U second) if (isIntegral!T &&
isFloatingPoint!U)
{
return first == 1;
}
bool testRoundTrip(U, T)(U first, T second) if (isIntegral!T &&
isFloatingPoint!U)
{
return second == 2;
}
void main(){
int x = 1;
double y = 1.1;
assert(testRoundTrip(x, y));
x = 2;
y = 2.2;
assert(testRoundTrip(y, x));
assert(testRoundTrip(1, 1.1));
assert(testRoundTrip(2.2, 2));
}
More information about the Digitalmars-d-learn
mailing list