名前空間
変種
操作

std::basic_string_view<CharT,Traits>::empty

From cppreference.com
 
 
 
 
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)
コンテナまたは配列のサイズを返す
(関数テンプレート) [編集]
(C++17)
コンテナが空かどうかをチェックする
(function template) [編集]
文字列が空かどうかをチェックする
(std::basic_string<CharT,Traits,Allocator> の public メンバ関数) [編集]
English 日本語 中文(简体) 中文(繁體)