Open utterances-bot opened 3 years ago
Both clang and gcc(https://godbolt.org/z/7ncaqKhz8) do not support this feature. Is this new feature pipelined in c++23?
yep, @nickhuang99 - as I wrote at the bottom of the article: As of August 2021, this feature works only in one major compiler - MSVC, starting from Visual Studio 2019 16.10
interesting ah well something to look forward to.
splitSV? where is the def?
@kobi-ca skipped in text, but it's defined in the playable version at CE
see more comments at reddit/cpp: https://www.reddit.com/r/cpp/comments/pehseo/constexpr_vector_and_string_in_c20_and_one_big/
My constexpr solution
Well, below is my constexpr solution for the last problem:
auto find_longest(const std::string_view s) noexcept -> std::string_view
{
auto splitted = s | std::views::split(" "sv);
auto max_elem = std::ranges::max(splitted, {}, [](const auto x) { return std::string_view{ x }.size(); });
return max_elem;
}
constexpr auto max = find_longest("Hi, it's TheMR from Pakistan");
Try it: https://godbolt.org/z/55dabn1Tf
Apparently, constexpr dynamically allocated memory IS possible with lambdas.
Create a lambda that makes a vector, and use another lambda to create an array
constexpr vector and string in C++20 and One Big Limitation - C++ Stories
constexpr started small in C++11 but then, with each Standard revision, improved considerably. In C++20, we can say that there’s a culmination point as you can even use std::vector and std::string in constant expressions! Let’s look at use cases, required features to make it work, and finally, one significant limitation that we might want to solve in the future.
https://www.cppstories.com/2021/constexpr-vecstr-cpp20/