• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <typeinfo>

    std::type_info::before

    bool before(const type_info& rhs) const;          // C++03
    bool before(const type_info& rhs) const noexcept; // C++11
    

    概要

    2つの型の照合順序を比較する

    戻り値

    2つの型の照合順序を比較し、*thisrhsより先行していればtrueを返し、そうでなければfalseを返す。

    この関数は内部実装で使用される関数であるため、継承関係や宣言順序は必ずしも関係があるわけではない。

    例外

    投げない

    #include <iostream>
    #include <typeinfo>
    
    struct A {};
    struct B {};
    
    int main()
    {
      const std::type_info& a = typeid(A);
      const std::type_info& b = typeid(B);
    
      std::cout << std::boolalpha << a.before(b) << std::endl;
    }
    

    出力例

    true
    

    参照