Tuple和TypeTuple有什么区别?我查看了库中的示例代码,但它们看起来很相似。我如何决定使用哪一个?有一个很好的理由,为什么Tuple在std.typecons中,但TypeTuple在std.typetuple中?Tuple和TypeTuple在D
6
A
回答
4
一个Tuple
是数据类型,由您指定的字段集合组成。
A TypeTuple
只是编译器在编译时知道的“一堆东西”;它在运行时不存在。
(相反,它的名字,一个TypeTuple
可以容纳相当多什么 - !不只是种)
+0
我觉得你的答案和Michal的应该合并成一个。 – Arlen 2011-05-20 04:47:25
3
元组std.typecons正常值的普通元组。
typetuple std.typetuple是元组的类型。它可以在编译时使用,就像在这个示例函数中那样,它允许将函数的允许类型限制为int,long和double。
void foo (T) (T arg) {
static assert staticIndexOf!(T,TypeTuple!(int, long, double)) != -1,
T.stringof ~" is not allowed as argument for foo");
}
3
元组
是变量的集合(例如一个结构),而TypeTuple是你可以在模板检查
Tuple!(int,"index",real,"value") var;
使用类型的集合定义了与一个var.index int和VAR的可变.value的真正
时要检查你的模板实例是否使用了正确类型的一个TypeTuple使用
相关问题
- 1. PyInstaller和Python3.6 - Tuple Index
- 2. 区别:d [count]和d [count]
- 3. 为什么list(),dict()和tuple()比[],{}和()慢?
- 4. 将Tuple字符串转换为Tuple
- 5. Tuple切换Tuple数组中的位置
- 6. 为什么Scala在拆包Tuple时构造一个新的Tuple?
- 7. 复制std :: tuple
- 8. Haskell List to Tuple
- 9. boost tuple错误
- 10. Python List/Tuple
- 11. Be-friend'ing std :: tuple
- 12. F#。 Tuple与否
- 13. “d = dict()”和“d = {}”之间的区别
- 14. StaticCRT(LIBCMT(D))和DynamicCRT(MSVCRT(D))冲突
- 15. 垃圾回收和Apache Commons Tuple Pair
- 16. 什么是Scala版本的ArrayList和Tuple?
- 17. 在d
- 18. 链接glfw和D
- 19. D和伪终端
- 20. 遍历boost :: hana :: tuple
- 21. RSA编码和解码[e,d]。在python中查找e和d ..更新
- 22. 什么是gsub(/(\ d {4})\ /(\ d \ d)\ /(\ d \ d)\ /(。*)/,'\ 1- \ 2- \ 3- \ ) 意思?
- 23. 使用正则表达式识别窗体\ d \ d \ d \ d \ d \ d的日期
- 24. “共享”和“__gshared”关键词在d
- 25. 为什么\ d \ +或\ d +在这里不等于\ d *?
- 26. @d在''xterm -display @d'中的含义
- 27. 在Tuple中使用索引方法?
- 28. 在tr1 :: hash中使用boost :: tuple
- 29. 在Apache Pig中为Tuple创建模式
- 30. Python 2.7:%d,%s和float()
注意,这些用于特殊目的,基于库的解决方案。 它们基于D的内置元组概念:http://www.digitalmars.com/d/2.0/tuple.html – Trass3r 2011-05-19 23:32:15
@ Trass3r所以你说D中有3种类型的元组? – Arlen 2011-05-20 01:09:38
不,我只是说* *语言*只有一个元组的概念。 您提到的Tuple和TypeTuple是基于库的。 顺便说一句,原始元组可以“创建”与'模板DTuple(T ...){别名T DTuple;}' – Trass3r 2011-05-20 12:57:38