std::basic_string_view<CharT,Traits>:: empty
From cppreference.net
<
cpp
|
string
|
basic string view
|
constexpr
bool
empty
(
)
const
noexcept
;
|
(C++17以降) | |
ビューに文字が存在しないかどうかをチェックします。つまり、
size()
==
0
かどうかを確認します。
目次 |
パラメータ
(なし)
戻り値
true ビューが空の場合、 false それ以外の場合。
計算量
定数。
例
このコードを実行
#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]); }
出力例:
'' has 0 character(s); emptiness: true './a.out' has 7 character(s); emptiness: false
関連項目
|
文字数を返す
(public member function) |
|
|
最大文字数を返す
(public member function) |
|
|
(C++17)
(C++20)
|
コンテナまたは配列のサイズを返す
(function template) |
|
(C++17)
|
コンテナが空かどうかをチェックする
(function template) |
|
文字列が空かどうかをチェックする
(
std::basic_string<CharT,Traits,Allocator>
のpublic member function)
|