std::basic_..._view::empty(3)
π NAME π
std::basic_string_view::empty β std::basic_string_view::empty
okay so welcome to the C++ Standard Libary manual, bestie β this is the std::basic_..._view::empty(3) page, and it's literally all about checking if a string view is empty. C++17 girlies, this one's for you.
πΈ Synopsis πΈ
constexpr bool empty() const noexcept; (since C++17)
(until C++20)
[[nodiscard]] constexpr bool empty() const noexcept; (since C++20)
This is the vibe check for the view: it checks if the view has no characters, i.e. whether size() == 0. No cap.
The plain constexpr cut is the since C++17 / until C++20 era; C++20 onward adds [[nodiscard]]. Periodt.
π Parameters π
(none) β literally zero parameters. The function takes nothing, bestie.
π«Ά Return value π«Ά
true if the view is empty, false otherwise. That's the whole tea. β
β‘ Complexity β‘
Constant. Periodt. That's it.
π§ Example π§
okay so here's the whole demo, exactly as it is:
// Run this code
#include <iostream>
#include <string_view>
// Print a string surrounded by single quotes, its
// length and whether it is considered empty.
void check_string(std::string_view ref)
{
std::cout << std::boolalpha
<< "'" << ref << "' has " << ref.size()
<< " character(s); emptiness: " << ref.empty() << '\n';
}
int main(int argc, char **argv)
{
// An empty string
check_string("");
// Almost always not empty: argv[0]
if (argc > 0)
check_string(argv[0]);
}
π Possible output π
Possible output, slay:
'' has 0 character(s); emptiness: true
'./a.out' has 7 character(s); emptiness: false
π₯ See also π₯
the cross-reference corner is a little chaotic, but every line is here:
sizeβ returns the number of characterslengthβ (public member function)max_sizeβ returns the maximum number of characters (public member function)sizessizeβ returns the size of a container or array(C++17)β (function template)(C++20)emptyβ checks whether the container is empty(C++17)β (function template)- checks whether the string is empty
emptyβ (public member function ofstd::basic_string<CharT,Traits,Allocator>)
shoutout to source/version http://cppreference.com and the date stamp 2024.06.10 β this was the std::basic_..._view::empty(3) page, mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms