Supposing I have 4 or 5 mutually exclusive overloads of a function using enable_if as a function parameter with a default argument, is there any way for me to provide an additional version of this function that handles every other case, without manually combining all the previous cases and using another enable_if? For example: template<class T> void foo(typename enable_if<condition1>::type* dummy=0) {} template<class T> void foo(typename enable_if<condition2>::type* dummy=0) {} template<class T> void foo(typename enable_if<condition3>::type* dummy=0) {} template<class T> void foo(typename enable_if<condition4>::type* dummy=0) {} template<class T> void foo() { //default instantiation that gets invoked if and only if all of the other overloads fail }
AMDG Zachary Turner wrote:
Supposing I have 4 or 5 mutually exclusive overloads of a function using enable_if as a function parameter with a default argument, is there any way for me to provide an additional version of this function that handles every other case, without manually combining all the previous cases and using another enable_if?
Not that I know of. You would have to make the fallback less specialized than any of the enable_if'ed overloads. In Christ, Steven Watanabe
Zachary Turner wrote:
Supposing I have 4 or 5 mutually exclusive overloads of a function using enable_if as a function parameter with a default argument, is there any way for me to provide an additional version of this function that handles every other case, without manually combining all the previous cases and using another enable_if?
For example:
template<class T> void foo(typename enable_if<condition1>::type* dummy=0) {}
template<class T> void foo(typename enable_if<condition2>::type* dummy=0) {}
template<class T> void foo(typename enable_if<condition3>::type* dummy=0) {}
template<class T> void foo(typename enable_if<condition4>::type* dummy=0) {}
template<class T> void foo() { //default instantiation that gets invoked if and only if all of the other overloads fail }
template<class T> void foo(...) { //default instantiation that gets invoked if and only if all of the
other overloads fail }
Note, however, it will only work if you call foo<T>(0) and not if you call foo<T>().
participants (3)
-
Mathias Gaunard
-
Steven Watanabe
-
Zachary Turner