I have a template <bool P> class Foo
with lots of code in it. I want to be able to convert Foo<true>
's into Foo<false>
's, i.e. have an operator Foo<false>()
method. But the compiler doesn't like such a method existing for Foo, it only likes it for Foo<true>
, and gives a warning about how the "operator will not be called for implicit or explicit conversions" (GCC 5.4.x)
It doesn't seem like I can use SFINAE for this: std::enable_if
works with types; and a value-variant I tried out (where the true case has a value
rather than a type
member) didn't help either.
How can I get this operator to only be compiled for Foo<false>
(other than specializing Foo<false>
different and duplicating all of my code)?
My best attempt so far has been:
template <bool P> class Foo {
// etc. etc.
template <bool OtherValue>
operator Foo<OtherValue>()
{
static_assert(OtherValue, "You should not be using this conversion!");
// conversion code here
return Foo<false>(args,go,here);
}
}