Open hgducharme opened 1 year ago
When trying to have magic_bitboards::init()
resolve at compile time, I get the following error:
error: constexpr function's return type 'magic_bitboards::(anonymous namespace)::std::array<std::vector<Bitboard>, Square::NUMBER_OF_SQUARES>' is not a literal type
constexpr std::array<std::vector<Bitboard>, Square::NUMBER_OF_SQUARES> calculateBlockerVariations(HashingParameters const * hashingParametersLookup)
Basically, any function that returns std::array<std::vector<Bitboard>, Square::NUMBER_OF_SQUARES>
can not be a constexpr
because std::array<std::vector<Bitboard>, Square::NUMBER_OF_SQUARES>
is not a literal type.
C++ requires that a constexpr
function return a literal type. std::vector
is not considered a literal type since it involves dynamic memory allocation. To make std::array<std::vector<Bitboard>, Square::NUMBER_OF_SQUARES>
a literal type we need to switch to a fixed width container like an array of arrays, where we know the size at compile time. Something like
std::array<std::array<Bitboard, MaxSize>, Square::NUMBER_OF_SQUARES>` where `MaxSize` is known at compiled time.
Figure out how to make a lot of the deterministic, precalculated variables such as magic bitboards, attack tables, etc.
constexpr
types. Usually when I do this I get redundant symbol definition compiler errors