• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function template
    <type_traits>

    std::is_pointer_interconvertible_with_class

    namespace std {
      template<class S, class M>
      constexpr bool is_pointer_interconvertible_with_class(M S::*m) noexcept;
    }
    

    概要

    メンバポインタmがクラスSのポインタの間でポインタ相互交換可能かを判定する。

    適格要件

    S完全型であること。

    戻り値

    Sスタンダードレイアウト型Mはオブジェクト型であり、mはヌルポインタではなく、型Sのオブジェクトsがサブオブジェクトs.*mポインタ相互交換可能であるときに限ってtrueを返す。それ以外の場合はfalseを返す。

    例外

    投げない

    #include <type_traits>
    
    struct A { int a; };
    struct B { int b; };
    struct C: A, B {};
    
    int main()
    {
      static_assert( std::is_pointer_interconvertible_with_class<A>( &A::a ));
      static_assert( std::is_pointer_interconvertible_with_class<B>( &B::b ));
    
      // 見た目に反して &C::b は int(B::*) 型を持つためS=Bに型推論されてしまう。
      static_assert( std::is_pointer_interconvertible_with_class( &C::b ));
      // テンプレートパラメータS=Cを明示することで M(C::*) の検査となる。
      // このケースではCはスタンダードレイアウトクラスではなくfalseとなる。
      static_assert(!std::is_pointer_interconvertible_with_class<C>( &C::b ));
    }
    

    出力

    バージョン

    言語

    • C++20

    処理系

    関連項目

    参照