public member function
<typeinfo>

std::type_info::before

bool before (const type_info& rhs) const;
bool before (const type_info& rhs) const noexcept;
比較型別的順序
返回某個實現定義的順序中,該型別是否位於 rhs 所標識的型別之前。

這種實現定義的順序不一定與大小、繼承關係或宣告順序相關,並且可能因程式而異。

引數

rhs
一個標識型別的type_info物件。

返回值

如果由 *this 標識的型別被認為位於 rhs 標識的型別之前,則返回 true,否則返回 false

示例

1
2
3
4
5
6
7
8
9
10
11
12
// ordering types
#include <iostream>   // std::cout
#include <typeinfo>   // operator typeid

int main() {
  if ( typeid(int).before(typeid(char)) )
    std::cout << "int goes before char in this implementation.\n";
  else
    std::cout << "char goes before int in this implementation.\n";

  return 0;
}

可能的輸出
char goes before int in this implementation.


異常安全

無異常保證:此成員函式從不丟擲異常。

另見