7 ms·
It enables users to process string at compile time. You can implement a constexpr getRFC3339DateString(int year, int month, int day) -> string and then construc
by hudsonwillis 3y ago
It enables users to process string at compile time. You can implement a constexpr getRFC3339DateString(int year, int month, int day) -> string and then construct a constexpr string list.
- kccqzy 3y agoBut what can you do with that string list afterwards? You can't store it anywhere to be accessed at run time, can you?
- Chabsff 3y agoThe important part is that all the intermediate strings used during the computation are constexpr, to guarantee that the work happens during compilation. Also, constexpr symbols can be demoted to regular const as needed by the compiler if necessary, such as when getting a pointer to one. constexpr doesn't mean "compile-time only", it means "compile-time compatible"
- lldb 3y agoRight - you can use the std::string at compile time but since it allocates dynamically you need to copy to a fixed size char[]/std::array to use at runtime.