std::enable_if
needs to depend on a parameter of the member template itself.
template <typename TagType>
class foo
{
public:
template <typename U = TagType>
typename std::enable_if<
std::is_base_of<std::bidirectional_iterator_tag,
U>::value,
foo>::type
operator --() {
return *this;
}
};
SFINAE will work as expected.
int main() {
foo<std::random_access_iterator_tag> f;
foo<std::forward_iterator_tag> f2;
--f; // fine
--f2;
}
main.cpp:24:3: error: no match for 'operator--' (operand type is 'foo<std::forward_iterator_tag>')
--f2;