lundi 23 février 2015

Using CRC32 algorythm to hash string at compile-time

Basically I want in my code to be able to do this:



Engine.getById(WSID('some-id'));


Which should get transformed by



Engine.getById('1a61bc96');


just before being compiled into asm. So at compile-time.


This is my try



constexpr int WSID(const std::string& str) {
boost::crc_32_type result;
result.process_bytes(str.data(), str.length());
return result.checksum();
}


But I get this when trying to compile with MSVC 18 (CTP November 2013)



error C3757: 'const std::string &': type not allowed for 'constexpr'
error C3249: illegal statement or sub-expression for 'constexpr' function

Aucun commentaire:

Enregistrer un commentaire