mardi 2 février 2016

Achieving an SFINAE-like effect with an if-else

I would like to be able to write something like

template <typename T> void foo() {
    // ...
    if (is_nice<T>::value) {
        bar_which_is_defined_only_for_nice_types<T>();
    }
}

However, when I try to compile this (g++ 4.9.3, no optimization) I get a complaint about bar_which_is_defined_only_for_nice_types. How can I achieve the desired effect without resorting to 2 definitions of foo()?

Aucun commentaire:

Enregistrer un commentaire