V2EX  ›  英汉词典

Type Traits

释义 Definition

Type traits(类型特征/类型萃取)指一组用于在编译期查询、判断或转换“类型信息”的工具(常见于 C++ 模板元编程)。例如判断某个类型是否为整数、是否可拷贝、是否为指针,或获得去掉引用/const 后的类型等。(在不同语言/语境中也可泛指“类型的属性”。)

发音 Pronunciation (IPA)

/taɪp treɪts/

例句 Examples

Type traits help the compiler choose the right overload.
类型特征帮助编译器选择正确的重载函数。

Using type traits like std::is_integral and std::remove_reference, you can write templates that adapt to different input types without runtime cost.
使用诸如 std::is_integralstd::remove_reference 这类类型特征,你可以编写能适配不同输入类型、且没有运行时开销的模板代码。

词源 Etymology

type 来自希腊语 typos(印记、模子),引申为“类型、范式”;trait(s) 来自拉丁语 tractus 相关词族(特征、性质)。在现代编程语境中,type traits 作为术语流行于 C++ 模板体系,用来表示“可在编译期获取的类型性质/规则集合”。

相关词 Related Words

文学与著作中的用例 Literary / Notable Works

  • The C++ Programming Language — Bjarne Stroustrup(讨论模板与类型系统相关内容时常涉及 type traits)
  • Effective Modern C++ — Scott Meyers(涉及 std::enable_ifstd::decay 等与 type traits 紧密相关的写法)
  • C++ Templates: The Complete Guide — David Vandevoorde, Nicolai M. Josuttis(系统讲解模板技术与 type traits 体系)
  • ISO C++ Standard(标准库 <type_traits> 标头定义并规范了大量 type traits)
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1688 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 11ms · UTC 16:26 · PVG 00:26 · LAX 09:26 · JFK 12:26
♥ Do have faith in what you're doing.