Compile-time loop loops wrong
I just cannot seem to find why this weird behaviour.
Consider:
Code:
template<unsigned int N>
class Test
{
private:
template<unsigned int Row, unsigned int Col>
struct PropagatorLoop
{
void operator () () //(me_t& parent)
{
//Gecode::when(parent, parent.m_Board(Col, Row), reinterpret_cast<void (*)(Gecode::Space&)>(&XNQueens::Propagator<Row, Col>), nullptr, Gecode::ICL_DEF);
PropagatorLoop<Row, Col + 1>()(/*parent*/);
}
};
template<unsigned int Row>
struct PropagatorLoop<Row, N>
{
void operator () ()// (me_t& parent)
{
std::cout << N;
PropagatorLoop<Row + 1, 0>()(/*parent*/);
}
};
template<>
struct PropagatorLoop<N, N>
{
void operator () ()// (me_t& parent)
{
}
};
public:
Test() { PropagatorLoop<0, 0>()(); }
};
int main()
{
Test<8>();
}
When calling PropagatorLoop<0, 0>()(),
template<unsigned int Row>
struct PropagatorLoop<Row, N>
matches instead of
template<unsigned int Row, unsigned int Col>
struct PropagatorLoop
I just cannot understand why (clearly, we are calling <0, 0>, not <0, 8>). If I replace "N" with 8, it works as expected (at least for the beginning of the loop).
I only tested on MSVC. Anyone have any insight into this behaviour?