摘要:
我想通过子类型在多个结构间共享一个数组,我尝试了这个,发现了一些奇怪的行为. class SharedArray(T) { public T[] array; alias array this; // 子类型 } alias Filenames = SharedArray!(string); str 阅读全文
posted @ 2022-01-19 22:29
zjh6
阅读(14)
评论(0)
推荐(0)
摘要:
struct S { int a; enum size = S.sizeof;//冻结构大小 mixin("int b;"); } 阅读全文
posted @ 2022-01-19 21:56
zjh6
阅读(13)
评论(0)
推荐(0)
摘要:
string generate(string typeName)() { return "%s bla;".format(typeName); } void main() { mixin(generate!"int"); bla = 5; }//生成类型. 阅读全文
posted @ 2022-01-19 21:33
zjh6
阅读(16)
评论(0)
推荐(0)
摘要:
我得到编译错误.但它不在foo中,它在bar中.它说: 错误:onlineapp.bar!(foo)模板实例与x=foo(T)(T v)的bar(alias x)()模板声明不匹配,必须满足__traits(compiles,x(1))约束. 我一般是提取约束模板并实际用该类型调用约束中的函数,然后 阅读全文
posted @ 2022-01-19 20:37
zjh6
阅读(20)
评论(0)
推荐(0)
摘要:
import std.meta; alias Numerics = AliasSeq!(byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real, char, wchar, dchar); enum convert 阅读全文
posted @ 2022-01-19 19:24
zjh6
阅读(13)
评论(0)
推荐(0)
摘要:
包装器: struct Wrapper(alias sym) { import std.format: format; template opDispatch(string name, Args...) //非DRY,可能有更好方法. if (__traits(compiles, mixin(`__ 阅读全文
posted @ 2022-01-19 16:10
zjh6
阅读(22)
评论(0)
推荐(0)
摘要:
消除歧义方法: //假设另外有个get可用, import curl = std.curl; // ... curl.get(whatever); import std.curl; alias curlGet = std.curl.get; // ... curlGet(whatever); sta 阅读全文
posted @ 2022-01-19 13:10
zjh6
阅读(44)
评论(0)
推荐(0)
摘要:
import mir.random; import mir.random.variable; RVector rngexample(int n) { auto gen = Random(unpredictableSeed); auto rv = uniformVar(-10, 10); // [-1 阅读全文
posted @ 2022-01-19 09:38
zjh6
阅读(16)
评论(0)
推荐(0)
摘要:
import std; version(traceFuncCalls) { // 从中提取参数元组的假函数 void locusFunc(string file = __FILE__, size_t line = __LINE__,string func = __FUNCTION__); // 绑定 阅读全文
posted @ 2022-01-19 09:29
zjh6
阅读(19)
评论(0)
推荐(0)
摘要:
可用立即调用的串字面来解决: enum string values = () { string result = "value.x"; if (L != 1) { result ~= ",value.y"; } if (L != 2) { result ~= ",value.z"; } if (L 阅读全文
posted @ 2022-01-18 22:34
zjh6
阅读(12)
评论(0)
推荐(0)
浙公网安备 33010602011771号