DTemplatesDecompositionAndValueTypes:D模板:分解和值类型

时间:2024-03-07 21:27:25
【文件属性】:

文件名称:DTemplatesDecompositionAndValueTypes:D模板:分解和值类型

文件大小:2KB

文件格式:ZIP

更新时间:2024-03-07 21:27:25

D模板基础:参数推导和值类型 介绍 因此,您已经开始编写D代码,并乐于编写简单的模板(例如下面的模板)来计算点积。 // value.d import std.stdio : writeln; import std.traits : isFloatingPoint; /* To compile: dmd value.d && ./value */ T dot (T)(T[] x, T[] y) if (isFloatingPoint ! T) { T ret = 0 ; foreach (i; 0 .. x.length) ret += x[i] * y[i]; return ret; } void main () { auto x = [ 1.0 , 2.0 , 3.0 ]; writeln( " dot: " , x.dot(x)); } 模板参数


【文件预览】:
DTemplatesDecompositionAndValueTypes-master
----README.md(3KB)

网友评论