本文介绍了什么样的“特质"?在C ++ 0x标准中使用/定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

C ++中的特征封装了一系列操作,这些操作允许算法或数据结构以实例化该类型的类型进行操作. char_traits 是将 string -和文件所需功能分组的示例.

A trait in C++ encapsulates a family of operations that allow an Algorithm or Data Structure to operator with that type with which it is instantiated. char_traits are an example for grouping string- and file-required functions.

但并非所有特征的名称中都带有特征",对吗?我想到了 numeric_limits .这也是特质"吗?即使其中没​​有名称"trait"?

But not all traits have "trait" in their name, right? numeric_limits comes to mind. Is this a "Trait", too? Even without the name "trait" in it?

那么,还有其他可以/应该被认为是特质"的模板吗?除了我发现的示例之外:

So, are there other Templates that could/should be considered a "Trait"? Besides the examples I found:

  • allocator_traits 如何获取内存
  • pointer_traits 如何间接访问对象
  • type_traits 元编程
  • char_taits 表示符号序列
  • iterator_traits 如何前进,后退和到达元素
  • regex_traits 用于...正则表达式.
  • allocator_traits how to get memory
  • pointer_traits how to access an object indirectly
  • type_traits meta programming
  • char_taits for sequence of symbols
  • iterator_traits how to get forward, backward and to the element
  • regex_traits for... regexes.

我想,我要问的是,特征是否有纯定义?

I guess, what I am asking, too, is there a pure definition for traits?

我特别不确定的是:

    上面提到的
  • numeric_limits
  • < chrono> 的自定义特征" [20.11.4],即 duration_values
  • 关于散列有什么意义?函子 hash<> 是否可以视为特征?
  • 如果是这样,不是所有需求都是特征",例如"CopyAssignable"等吗?
  • 然后,被遗弃的概念"是最终的特征"-定义吗?
  • numeric_limits mentioned above
  • <chrono>s customization "traits", [20.11.4], i.e. duration_values
  • what about Hashing? Can the functor hash<> be considered to be a trait?
  • If thats the case, are not all requirements "traits", like "CopyAssignable", etc?
  • And then, are the abandoned "Concepts" the ultimate "trait"-Definition?

更新:这个问题究竟是什么使特质成为特质,这个问题在细节上似乎有点争议.也许可以回答另一个问题:是否有详尽的清单列出哪些特质类是C ++ 0x的新特性,哪些已经在C ++ 03中使用?也许有人知道链接到某个地方?

Update: The question what exactly makes a trait a trait seems a bit controversy in the details. Maybe a another question could be answered: Is there a comprehensive list which of the trait-like classes are new to C++0x, and which ones have already been in C++03? Maybe someone knows of a link to somewhere?

推荐答案

  • * numeric_limits *绝对表示数字类型的一组特征.
  • 所有要求,例如"CopyAssignable"等,实际上都是特征,请参见关于特征的这篇论文

    对于其他人,我不能发表评论,但有疑问时:

    For the others I cannot comment but when in doubt:

    更新:仅对霍华德提供的广泛清单做出一小部分贡献:

    Update: to just make my small contribution to the extensive list Howard provided:

    我误以为TR1的 type特质 regex特质属于技术上不是C ++ 0x中新特性束的一部分(即使新的即将发布的标准已大大扩展了类型特征).请参阅霍华德对此的评论和澄清.

    I was wrongly under the impression that the type traits and regex traits beeing part of the TR1 are technically not part of the new traits bunch in C++0x(even though the type traits have been greatly extended by the new upcoming standard).See Howard's comment and clarification about that.

    这篇关于什么样的“特质"?在C ++ 0x标准中使用/定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    1403页,肝出来的..

09-06 10:18