Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::convertible_to

      From cppreference.com
      <cpp‎ |concepts
       
       
      Concepts library
       
      Defined in header<concepts>
      template<class From,class To>

      concept convertible_to=
         std::is_convertible_v<From, To>&&
          requires{
             static_cast<To>(std::declval<From>());

         };
      (since C++20)

      The conceptconvertible_to<From, To> specifies that an expression of the same type and value category as those ofstd::declval<From>() can be implicitly and explicitly converted to the typeTo, and the two forms of conversion produce equal results.

      Contents

      [edit]Semantic requirements

      convertible_to<From, To> is modeled only if, given a functionfun of typestd::add_rvalue_reference_t<From>() such that the expressionfun() isequality-preserving,

      • Either
        • To is neither an object type nor a reference-to-object type, or
        • static_cast<To>(fun()) is equal to[]()-> To{return fun();}(), and
      • One of the following is true:
        • std::add_rvalue_reference_t<From> is not a reference-to-object type, or
        • std::add_rvalue_reference_t<From> is an rvalue reference to a non-const-qualified type, and the resulting state of the object referenced byfun() is valid but unspecified after either expression above; or
        • the object referred to byfun() is not modified by either expression above.

      [edit]Equality preservation

      Expressions declared inrequires expressions of the standard library concepts are required to beequality-preserving (except where stated otherwise).

      [edit]References

      • C++23 standard (ISO/IEC 14882:2024):
      • 18.4.4 Conceptconvertible_to [concept.convertible]
      • C++20 standard (ISO/IEC 14882:2020):
      • 18.4.4 Conceptconvertible_to [concept.convertible]

      [edit]See also

      checks if a type can be converted to the other type
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/concepts/convertible_to&oldid=177880"

      [8]ページ先頭

      ©2009-2025 Movatter.jp