Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::holds_alternative

      From cppreference.com
      <cpp‎ |utility‎ |variant
       
       
      Utilities library
       
       
      Defined in header<variant>
      template<class T,class...Types>
      constexprbool holds_alternative(conststd::variant<Types...>& v)noexcept;
      (since C++17)

      Checks if the variantv holds the alternativeT. The call is ill-formed ifT does not appear exactly once inTypes...

      Contents

      [edit]Parameters

      v - variant to examine

      [edit]Return value

      true if the variant currently holds the alternativeT,false otherwise.

      [edit]Example

      Run this code
      #include <cassert>#include <string>#include <variant> int main(){std::variant<int,std::string> v="abc";assert(not std::holds_alternative<int>(v));assert(std::holds_alternative<std::string>(v));}

      [edit]See also

      returns the zero-based index of the alternative held by thevariant
      (public member function)[edit]
      reads the value of the variant given the index or the type (if the type is unique), throws on error
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/variant/holds_alternative&oldid=172845"

      [8]ページ先頭

      ©2009-2026 Movatter.jp