Kompilieren Sie die Zeitmemcpy von Double nach Std :: int64_tC++

Programme in C++. Entwicklerforum
Anonymous
 Kompilieren Sie die Zeitmemcpy von Double nach Std :: int64_t

Post by Anonymous »

Ich möchte einen Doppel als std :: int64_t verwenden C ++ 17 zur Kompilierzeit
, da ich C ++ 17 std :: bit_cast nicht verfügbar bin. Eine nicht kompile Zeitlösung, die UB vermeidet, besteht darin, STD :: memcpy :

Code: Select all

inline std::int64_t toInt(const double a_val) {
std::int64_t val;
std::memcpy(&val, &a_val, 8);
return val;
}
Dies funktioniert jedoch nicht zum Kompilierzeit, da std :: memcpy kein konstanter Ausdruck ist. Wie kann dies zur Kompilierzeit ohne UB erreicht werden?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post