編譯器在此類情況下是很聰明的, 都可以在 編譯期 完成計算。 你的程序 能夠通過簡單的改造變成編譯期程序。 std::unordered_map 的 allocator 如果 自定義成 一個可以在連續内存上實現的 hash桶,那它也可以變相在編譯期使用 。发布于 2023-11-09 09:15・山西 ...
eternal.hppis a header-only C++ implementation ofconstexpr/compile-time maps and hash maps. It provides an API that is somewhat compatible withstd::map/std::unordered_map, but doesn't support insertion, or other modifications. It's main focus is inbinary size: it generates minimal code and...
constexpr int g() { return 7; } // OK int b[5 + g()]; // create an array of 12 ints (note: vs2013RC doesn't seem to support this) string literals // C++03 char* a = "string"; // C++11 char * a = u8"string"; // UTF-8 string char16_t* b = u"string"; // ...