mercredi 11 mai 2022

Compiler macro to compare byte size of types

Can this if-statement be replaced with a #if .... macro?
Possibly without having to include (too many) extra headers.

#include <cstdint>
#include <string>
///Parse a string to obtain a fixed width type
inline uint64_t stou64(const std::string& in) {
    if (sizeof(unsigned long) == sizeof(uint64_t)) {
        return std::stoul(in);
    } else {
        return std::stoull(in);
    }
}

Aucun commentaire:

Enregistrer un commentaire