C++ Type Traits

前端 未结 1 1741
醉酒成梦
醉酒成梦 2021-02-14 03:08

I understand they encode information about the type you instantiate them with, but how do they work? Say, for instance, the type trait std::is_class. How d

相关标签:
1条回答
  • 2021-02-14 03:44

    Some type traits, like std::is_class just use compiler intrinsics (aka built-ins). You cannot write these yourself without special support from the compiler.

    Type traits are mostly useful in generic context—you may want to specialize things based on the properties of types, or impose restrictions on template arguments. For example, an implementation of std::copy may use std::memcpy internally instead of an explicit loop when the iterators are pointers to PODs. This can be achieved with SFINAE.

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题