1

I want to specialize template based on parameter which, but if I remove template < bool which2 = which > compilation fails. Why? How to avoid repetition?

#include <iostream>

template < typename T, bool which >
class Node {
    T key;
public:
    template < bool which2 = which >
    typename std::enable_if < which2 == false, bool >::type operator < ( const Node & second );
    template < bool which2 = which >
    typename std::enable_if < which2 == true, bool >::type operator < ( const Node & second );

    Node ( ) {
        (*this) < (*this);
    }
};

template < class T, bool which >
template < bool which2 >
typename std::enable_if < which2 == false, bool >::type Node < T, which >::operator < ( const Node & second ) {
    std::cout << "false" << std::endl;
    return false;
}

template < class T, bool which >
template < bool which2 >
typename std::enable_if < which2 == true, bool >::type Node < T, which >::operator < ( const Node & second ) {
    std::cout << "true" << std::endl;
    return false;
}

template < typename T, bool which >
class BH {
    Node < T, which > node;
};

int main ( ) {
    BH < int, true > aa;
    return 0;
}
assp1r1n3
  • 173
  • 2
  • 8

0 Answers0