Boost C++ 库

one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

第 39 章。Boost.TypeIndex 4.2 - Boost C++ 函数库
PrevUpHomeNext

第 39 章。Boost.TypeIndex 4.2

根据 Boost 软件许可证版本 1.0 发布。(参见随附文件 LICENSE_1_0.txt 或在 https://boost.ac.cn/LICENSE_1_0.txt 复制)

有时需要在运行时获取和存储类型信息。在这种情况下,通常会使用诸如 &typeid(T) 或 C++11 类 std::type_index 这样的结构,但问题也由此开始。

  • typeid(T)std::type_index 需要运行时类型信息 (RTTI)。
  • 一些 typeid(T) 的实现错误地没有剥离类型中的 const、volatile 和引用。
  • 一些编译器存在 bug,无法正确地比较跨共享库的 std::type_info 对象。
  • 目前只有少数标准库实现提供了 std::type_index
  • 没有简单的方法可以存储类型信息而不剥离 const、volatile 和引用。
  • 没有一种方便且可移植的方法来获取人类可读的类型名称。
  • 没有简单的方法可以创建自己的类型信息类。

Boost.TypeIndex 库旨在解决所有这些问题。

[Note] 注意

T 在此表示类型。可以将其视为 template <class T> 中的 T


PrevUpHomeNext