News for hackers. Stuff that matters.
Re:Just how constexpr is C++20’s std:string? by criddell on Friday September 08, 2023 @05:05PM (#37439413)
Why not use a std::array? Otherwise won't you a second variable for the string length?
Re:Just how constexpr is C++20’s std:string? by hot_gril on Friday September 08, 2023 @05:23PM (#37439610)
`constexpr char kFoo[] = "bar"`, then kFoo can be used like an std::string and passed into things that take const std::string& or string_view. The length is part of that. Or is that actually doing a copy?
Re:Just how constexpr is C++20’s std:string? by vitus on Friday September 08, 2023 @05:44PM (#37439776)
For both const std::string& and std::string_view, you're (potentially) incurring a runtime invocation of strlen.

For const std::string&, you're further incurring a copy in order to create a temporary std::string.

Re:Just how constexpr is C++20’s std:string? by hot_gril on Saturday September 09, 2023 @02:11AM (#37442724)
Whoops. As you can maybe tell, the stuff I use C++ for isn't so much about performance.
Re:Just how constexpr is C++20’s std:string? by criddell on Friday September 08, 2023 @05:46PM (#37439799)
I think you still need the length though unless you can guarantee the string will never have any nulls in it. In Windows, there are API calls that take strings with embedded nulls (and that are typically terminated with a two nulls in a row).

So you might need to deal with a string that looks like "foo\0bar\0\0".