std::type_info::before(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… std::type_info::before

okay so this is the C++ Standard Library page (the original header says β€œC++ Standard Libary” β€” a typo icon, we stan 😭) for std::type_info::before, and bestie, it’s giving short-but-iconic energy. πŸ¦‹


🌸 NAME

std::type_info::before β€” literally std::type_info::before. That’s the whole name, no plot twist. πŸ’–


✨ Synopsis

bool before( const type_info& rhs ) const;           (until C++11)
bool before( const type_info& rhs ) const noexcept;  (since C++11)

Returns true if the type of this type_info precedes the type of rhs in the implementation’s collation order. No guarantees are given β€” none, zero, zilch β€” and in particular, the collation order can change between invocations of the same program. 😭 That’s the tea: it’s implementation-defined behavior, not a promise. πŸ’€


πŸŽ€ Parameters

  • rhs β€” another type information object to compare to. Basically the other type_info bestie in the comparison. 🫢

πŸ‘‘ Return value

true if the type of this type_info precedes the type of rhs in the implementation’s collation order. ✨


🌈 Example

// Run this code

#include <iostream>
#include <typeinfo>

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";
}

πŸ’« Possible output

char goes before int in this implementation.

πŸ’œ See also

  • operator== β€” checks whether the objects refer to the same type. πŸ‘―β€β™€οΈ
  • operator!= β€” also a public member function, and it’s removed in C++20. πŸ‘‹

πŸ’Œ Source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::type_info::before(3). Bye bestie, go get that collation order! πŸŽ€
πŸ“¦ where this page comes from