Let us give any data structure containing objects of std::string_view
:
std::vector<std::string_view> v{ "abc", "def" };
std::deque<std::string_view> d{ "abc", "def" };
std::set<std::string_view> s{ "abc", "def" };
Is it guaranteed by cpp standard, that these containers store objects of class std::string_view
which point to the string literals ended with null?
I mean is it safe to write code like this:
void foo(const char* ptr) {
printf("%s", ptr);
}
for (auto elem : v)
foo(elem.data());
for (auto elem : d)
foo(elem.data());
for (auto elem : s)
foo(elem.data());