I have a template similar to sumtype.match
:
--- s.d
struct S {}
template match(A...)
{
auto match(S){return 1;}
}
--- main.d
//import std.sumtype; // uncomment to get error
import s;
void main()
{
S s;
assert(s.match!(_ => _) == 1);
}
If I uncomment import std.symtype
, I get this error:
/sandbox/main.d(7): Error: `match` matches conflicting symbols:
assert(s.match!(_ => _) == 1);
^
/sandbox/s.d(2): template `s.match(A...)(S)`
template match(A...)
^
/dlang/dmd/linux/bin64/../../src/phobos/std/sumtype.d(1649): template `std.sumtype.match(handlers...)`
template match(handlers...)
So I'm trying to make my s.match
to be applicable to S
only.
My idea was to move match
inside S
:
--- s.d
struct S
{
template match(A...)
{
auto match(){return 1;}
}
}
--- main.d
import std.sumtype;
import s;
void main()
{
S s;
assert(s.match!(_ => _) == 1);
}
But after doing this, I got deprecation warning:
/sandbox/s.d(5): Deprecation: function `main.main.match!((_) => _).match` function requires a dual-context, which is deprecated
auto match(){return 1;}
^
/sandbox/main.d(7): instantiated from here: `match!((_) => _)`
assert(s.match!(_ => _) == 1);
^
How can I make this working without warnings and conflict with sumtype.match
?
(I don't want to rename match
)