I need conditional using member declaration.
template <bool> struct B;
template <> struct B<true> { void foo(); };
template <> struct B<false> { };
template <typename T>
struct A : public B<is_default_constructible<T>::value> {
using B<is_default_constructible<T>::value>::foo();
void foo(int) {}
};
This obviously doesn't work, because B<bool>::foo is not defined
in half the cases. How can I achieve that? To have B<>::foo()
visible in A<T> scope beside foo(int)?
This is my solution. I'm sure it's won't be the best but it gets the job done.
struct Ashould contain methods you want defined in both cases.In case of
B<false>, onlyvoid foo(int)is defined. In case ofB<true>, bothvoid foo(int)andvoid foo()are defined.Now I don't have to worry about
B<is_default_constructible<T>::value>::foo()not being defined in certain cases.