https://github.com/mcostalba/Stockfish/ ... aluate.cpp
template evaluate_pieces is defined after the function that calls it: do_evaluate
For some reason this works!
One can say, "yes but you have declared it in advance at the beginning of the file".
But actually, first for a template at instantiation time compiler should already know template definition, secondly even if I change correct declaration:
Code: Select all
template<PieceType Pt, Color Us, bool Trace>
Score evaluate_pieces(const Position& pos, EvalInfo& ei, Score* mobility, Bitboard* mobilityArea);
Code: Select all
template<PieceType Pt, Color Us, bool Trace>
Score evaluate_pieces();
This is really weird even for me, I guess it has to do with two phase look up and the fact that the calling site is itself a template with one of its template parameters 'Trace' that is also a parameter of evaluate_pieces. But I still miss the details and a full clear explanation.
Can someone (with knowledge) fully explain in details what's happening?
P.S: Because I don't like this kind of 'work by magic' behavior I have reshuffled the functions to be defined C-style from bottom to top, so to avoid this weirdness.