09 2022 档案

摘要:原文 void _messageBox(string title, int style, T...)(T args) { string s = format(args); /* etc... */ } alias _messageBox!(APPNAME, SWT.ICON_INFORMATION) 阅读全文
posted @ 2022-09-28 09:10 zjh6 阅读(11) 评论(0) 推荐(0) 编辑
摘要:是否可绕过IFTI强制显式类型参数.Mayonix有个解决方案 template foobar(T) { T realFoobar(T t) { return t; } alias foobar = realFoobar; } void main() { foobar(3); // 不能从别名推导. 阅读全文
posted @ 2022-09-28 09:03 zjh6 阅读(8) 评论(0) 推荐(0) 编辑
摘要:原文 仅在基类上提供正确重载,而派生类上包含不正确重载时,编译器不会检查基类重载.如果派生类没有任何重载,则它可以工作.例如: struct Foo { void foo(Bar b) { b.bar(this); } } struct Foobar {} struct Foobar2 {} cla 阅读全文
posted @ 2022-09-27 09:51 zjh6 阅读(29) 评论(0) 推荐(0) 编辑
摘要:原文 原文2 原文3 类 客户{ 公: 客户(){ 线=线程([本]{ io环境_.跑(); }); } 简单异步::协程::懒<极>异步连接(动 主机,动 端口){ 极 中=协待 工具::异步连接(主机,端口);//.1 协中 中;//.2 } ~客户(){ io环境_.停止(); 如(线.可合并 阅读全文
posted @ 2022-09-26 15:46 zjh6 阅读(17) 评论(0) 推荐(0) 编辑
摘要:原文 // C++模板类(第3方库) template<typename T, typename X> class Foo { // X为行为开关,但未实例化. T a, b; }; using FooFloat = Foo<float>; // 自己的 C++ 函数: void bar(FooFl 阅读全文
posted @ 2022-09-26 08:45 zjh6 阅读(4) 评论(0) 推荐(0) 编辑
摘要:原文 typedef union value_u { void *p; } value_t; typedef struct data_s { void *p; } data_t; void fn() { value_t a; const value_t b; // 错误:无法隐式转换`const(v 阅读全文
posted @ 2022-09-22 10:40 zjh6 阅读(11) 评论(0) 推荐(0) 编辑
摘要:原文 import std.algorithm : filter, map; import std.stdio; struct S { bool flag; auto method() { return [ 1 ].filter!(e => flag); } } void main() @safe 阅读全文
posted @ 2022-09-22 10:23 zjh6 阅读(10) 评论(0) 推荐(0) 编辑
摘要:原文 概述 该DIP为函数定义提出了短语法.新语法使用=>分隔函数头和函数体来代替左大括号和右大括号: int add(int x, int y) pure => x + y; 已在D语言中作为预览实现 原理(一致/简洁) D语言已支持函数字面的短语法.如: const succ = (int x) 阅读全文
posted @ 2022-09-21 20:03 zjh6 阅读(12) 评论(0) 推荐(0) 编辑
摘要:原文 目前在预览开关后面,C位域不好,仅有好处:让编译器帮助打包私有的,仅供内部使用的结构到更紧凑的内存布局中.不保证公共abi. D位域可能很好 假想的: ulong fields { msb : 1, _reserved: 62, lsb: 1, }; 可分解现有字段按定义来取结构中包含的位字段 阅读全文
posted @ 2022-09-20 10:01 zjh6 阅读(16) 评论(0) 推荐(0) 编辑
摘要:{ "buildTypes": { "debug-cov": { "buildOptions": ["debugMode", "debugInfo", "coverage"] } } } 定义新构建. 阅读全文
posted @ 2022-09-19 19:41 zjh6 阅读(8) 评论(0) 推荐(0) 编辑
摘要:原文 void main() { struct One { int entry = 1; @disable this(this); } One[] ones = [One(), One()]; import std.algorithm.iteration: map; import std.algor 阅读全文
posted @ 2022-09-19 09:26 zjh6 阅读(12) 评论(0) 推荐(0) 编辑
摘要:原文 auto res = firstAttr; while (res) { if (res.localName != localName || res.namespaceURI != namespaceURI) res = res._nextAttr; else break; } return r 阅读全文
posted @ 2022-09-18 09:53 zjh6 阅读(6) 评论(0) 推荐(0) 编辑
摘要:原来都实现了,参考这里 空 串大小(串&a,整&i){i=a.大小();} //基函数. 元<类...T>空 f(T&&...t){ 静 常式 整 I=型长...(T);静断(I%2==0); 每列<I/2>(串大小,t...); } 空 主(){ 串 a{"啊"},b{"啊啊"};整 i,j; f 阅读全文
posted @ 2022-09-17 21:38 zjh6 阅读(12) 评论(0) 推荐(0) 编辑
摘要:元<动...N>空 动作(整 c,符*参[]){ 串 e;解析参数(c,参,e);//只1个参. d.动作<N...>(e); }//N为值模板参数,主模板参数. 这里,元<动...N>,用动作模板参数,N可以自动匹配非类型参数,不然,以其他作为参数,只会限制你的模板能力. 这样,用动来表示非类型模 阅读全文
posted @ 2022-09-17 18:44 zjh6 阅读(9) 评论(0) 推荐(0) 编辑
摘要:fun! Dkdml() "打开当目录,当前目录.直接取,还没用" let s:sta="start ." silent call system(s:sta) endf 要上面这样打开,自己用start 加上目录,结果报错,说什么打开临时文件错误. 阅读全文
posted @ 2022-09-17 18:01 zjh6 阅读(63) 评论(0) 推荐(0) 编辑
摘要:串 s=打印串("啊啊",i,j,m); 这里的,啊啊被弄成什么符[4]类型. 元<可转为串...N>串 打印串(N&...n){ } 在这里却通不过,因为原来的概念是这样: 元<类 T>概念 可转为串=有一个<T,串,整,极> 如果,改成 元<类 T>概念 可转为串=有一个<T,串,整,极,常符* 阅读全文
posted @ 2022-09-16 09:53 zjh6 阅读(16) 评论(0) 推荐(0) 编辑
摘要:原文 struct c { uint a, b;} __gshared const c d = { 3, 4}; __gshared const e = &d.a; 我想: struct c { uint32_t a, b; uint32_t[] arr; } 取不了常成员地址. 在内存中的地址不是 阅读全文
posted @ 2022-09-14 10:46 zjh6 阅读(6) 评论(0) 推荐(0) 编辑
摘要:原文 'const'除外,它不是臭味,因为某些模板是成员函数.并且成员函数上的"const"不能留给推导,因为它恰好是函数可重载类型的一部分. 需要创建显示普通函数,成员函数及其模板上的每个函数属性的含义的二维表,并提出指导方针. const, inout, shared属性与@safe,@trus 阅读全文
posted @ 2022-09-14 10:33 zjh6 阅读(13) 评论(0) 推荐(0) 编辑
摘要:原文 不能用importC,需要下面在D中工作 typedef struct { uint32_t mask_limit; // 极限 uint32_t value_count; // 位段数 uint32_t data[]; // 位码 + 后面枚举值 } upb_MiniTable_Enum; 阅读全文
posted @ 2022-09-14 10:16 zjh6 阅读(18) 评论(0) 推荐(0) 编辑
摘要:前一篇简单示例 现在,改造虚函数,原来是这样的: 元<类 T>构 M{ 保护: 虚 极 多个(整 i,整 j){中 真;} 虚 空 处理(整 i,整 j){} ... }; 现在,这样: 元<类 T>构 M{ 保护: 元<类 S> 极 多个(本 S&&s,整 i,整 j){中 s.多个(i,j);} 阅读全文
posted @ 2022-09-13 17:45 zjh6 阅读(23) 评论(0) 推荐(0) 编辑
摘要:#include <常用> 构 A{ 元<类 S>空 f(本 S&&s){打印(s.i);} }; 构 B:A{ 整 i=20; }; 空 主(){ B b;b.f(); } 对喜欢奇异模板的,是重大利好. 阅读全文
posted @ 2022-09-13 17:37 zjh6 阅读(6) 评论(0) 推荐(0) 编辑
摘要:原文 import std.algorithm; struct Foo(R) { R r; int i; bool empty() @nogc nothrow pure @safe scope { return r.empty; } auto front() @nogc nothrow pure @ 阅读全文
posted @ 2022-09-13 10:58 zjh6 阅读(13) 评论(0) 推荐(0) 编辑
摘要:原文 unittest { import std.testing; static foreach (T; IrregularStructs) { T obj; // 可默认构造? T = NoDefaultCtor 失败. auto obj2 = obj; // 可复制? T = NoCopyCto 阅读全文
posted @ 2022-09-13 09:10 zjh6 阅读(12) 评论(0) 推荐(0) 编辑
摘要:原文 public: void server_init() { CreateThread(NULL, 0, &this.ClientThread, cast(PVOID)clientSocket, 0, NULL); } private: extern(Windows) DWORD ClientTh 阅读全文
posted @ 2022-09-12 10:27 zjh6 阅读(11) 评论(0) 推荐(0) 编辑
摘要:原文 import std; struct A { double val; bool isBig; } void main() { alias DListOfA = DList!A; DListOfA[string] temp; A a = {2.0, true}; DListOfA returnV 阅读全文
posted @ 2022-09-12 10:01 zjh6 阅读(21) 评论(0) 推荐(0) 编辑
摘要:原文 version(Windows) alias socket_t = size_t; else alias socket_t = int; 目前这样,太麻烦了.希望能够: alias socket_t = version(Windows) size_t else int; //或类似 alias 阅读全文
posted @ 2022-09-12 09:36 zjh6 阅读(15) 评论(0) 推荐(0) 编辑
摘要:我也反对丢弃二进制字面.虽然我不经常使用它们,但有几次我确实需要它们,我很高兴它们在那里.它是C缺少的D优点之一,如果放弃它会相当失望.不得不求助于模板来使用二进制字面会很痛苦. 八进制的丢弃也没有那么成功.应该选择0o 编译器仍在正确解析八进制字面. 0o对八进制完全有意义,就像0x对十六进制完全 阅读全文
posted @ 2022-09-11 11:14 zjh6 阅读(26) 评论(0) 推荐(0) 编辑
摘要:原文 module Console; //模块名, import std.string; import core.sys.windows.windows; class Console { public: HANDLE hIn; HANDLE hOut; this(HANDLE hIn, HANDLE 阅读全文
posted @ 2022-09-11 08:29 zjh6 阅读(11) 评论(0) 推荐(0) 编辑
摘要:最开始,以为静态变量好,结果,出现我需要同时使用该类变量,此时,就不能用全局静态变量. 因为,使用它多了,而后面全部改成类对象了. 不用全局静态变量,以前的就要出问题,以前的旧代码就都要改成类对象.使用旧代码时,要注意. 不然,直接使用,会犯大量错误! 使用老代码时,取名时,取新名.不要直接用写串, 阅读全文
posted @ 2022-09-10 18:43 zjh6 阅读(9) 评论(0) 推荐(0) 编辑
摘要:模板可以使用"template this",它们允许传递任何类型. template Test(this ThisType) { pragma(msg, ThisType); } void main() { alias T = Test!int; // Prints "int" } 这也适用于类模板 阅读全文
posted @ 2022-09-10 09:20 zjh6 阅读(11) 评论(0) 推荐(0) 编辑
摘要:原文 我想存储任意类型,要用ubyte数组.但要保存类型信息.用: SumType!(Tuple(int, string, double),Tuple(S, char)) 想出了存储创建时知道确切类型的λ. 因为按序列模板参数(又名可变参数)提供数据,可带带任意数据集. set()为@nogc的. 阅读全文
posted @ 2022-09-09 09:23 zjh6 阅读(20) 评论(0) 推荐(0) 编辑
摘要:原文 因为需要inet_ntop函数,我要包含Ws2tcpip.h头文件. 要复制 const char *inet_ntop(int af, const void *restrict src, char *restrict dst, socklen_t size); 声明为D: extern(C) 阅读全文
posted @ 2022-09-08 10:19 zjh6 阅读(14) 评论(0) 推荐(0) 编辑
摘要:原文 简化示例: lib.c int f(int x) { return x + 1; } app.d import lib; typeof(&__traits(getMember, lib, "f")) fptr; pragma(msg, typeof(fptr)); // extern (C) 阅读全文
posted @ 2022-09-08 09:50 zjh6 阅读(11) 评论(0) 推荐(0) 编辑
摘要:原文 规范说:类不变量是继承的,即,子类要满足基类不变量. import core.exception; class A { int i = 3; invariant { assert(i >= 2); } } class B : A { void setB(int v) { i = v; } in 阅读全文
posted @ 2022-09-08 09:36 zjh6 阅读(7) 评论(0) 推荐(0) 编辑
摘要:原文 import core.runtime; import std.stdio; import std.string; import core.sys.windows.windows; extern(Windows) int WinMain(HINSTANCE hInstance, HINSTAN 阅读全文
posted @ 2022-09-07 20:27 zjh6 阅读(14) 评论(0) 推荐(0) 编辑
摘要:原文 在语言中拥有ImportC有个非常酷的好处.使我们能够动态绑定到C库,而无需手动编写任何绑定代码! 窍门: 第1步:预处理C库头文件,以便可在D中导入它. 第2步:使用D的编译时内省来生成函数指针和相关的加载程序例程. 第3步:后续动作 第4步:利润! static import portau 阅读全文
posted @ 2022-09-07 08:46 zjh6 阅读(25) 评论(0) 推荐(0) 编辑
摘要:原文 void foo(string s) @safe pure nothrow @nogc in (s != "hello", "Invalid " ~ s) { } void main() {} 错误:不能在@nogc的deneme.foo函数中使用~符号. 但是该符号仅在即抛错误时使用,即不应 阅读全文
posted @ 2022-09-06 11:38 zjh6 阅读(14) 评论(0) 推荐(0) 编辑
摘要:原文 struct S(T, size_t memberCapacity = size_t.max) { static if (memberCapacity != size_t.max) { // 用户想要成员数组 T[memberCapacity] arr; void initMemberArra 阅读全文
posted @ 2022-09-06 11:08 zjh6 阅读(9) 评论(0) 推荐(0) 编辑
摘要:原文 想在栈上声明类. 可用scope存储类,参考 void main() @nogc { scope o = new Object(); } @nogc属性确保不使用垃集分配. @nogc属性由编译器强制保证没有堆分配,因此如果此处不使用带scope的new,就会报错. GC.disable()是 阅读全文
posted @ 2022-09-06 10:53 zjh6 阅读(10) 评论(0) 推荐(0) 编辑
摘要:原文 synchronized class SyncTable(KEY, VAL) { private VAL[KEY] table; auto require(KEY key) { return table.require(key); } } auto table = new shared Syn 阅读全文
posted @ 2022-09-06 09:48 zjh6 阅读(13) 评论(0) 推荐(0) 编辑
摘要:原文 如何取堆栈跟踪并打印到标准输出? 我考虑用UDA&__LINE__,但UDA不允许注入代码,太可惜了. 可参考. 这里 看起来druntime实现最终通过平台无关库接口依赖于C++异常处理ABI,这里 绑定定义. 基于表的异常处理, 注释说不用了,但可参考. 阅读全文
posted @ 2022-09-06 09:16 zjh6 阅读(9) 评论(0) 推荐(0) 编辑
摘要:原文 SumType不会像Algebraic那样尝试转发运算符到包含的值,因此要用tryMatch来访问. // 比较DataType[]和double[] import std.algorithm.comparison: equal; /+ 如果左边包含不能同`双精`比较的值,则抛异常 +/ al 阅读全文
posted @ 2022-09-06 08:59 zjh6 阅读(9) 评论(0) 推荐(0) 编辑
摘要:我不确定我是否完全理解工作原理.我知道操作系统为两者创建只读内存页面,如果要写入内存节,操作系统复制页面,在副本中写入,并且不会搞砸事情. 但接着问题是,如何标记内存为释放?分叉进程不能因为,它写入副本,那么如何同步呢? GC地址根是否在进程间共享?或分叉进程是否返回内存地址给父进程? 是,GC是否 阅读全文
posted @ 2022-09-05 20:29 zjh6 阅读(12) 评论(0) 推荐(0) 编辑
摘要:原文 Iain Iain首先介绍了dmd和druntime存储库合并的最新情况,他说大部分进展顺利.要去掉makefile. Max指出,dmd -i几乎可用来构建dmd,而后端只有一件事可以阻止它. Max Walter询问了他的80位浮点仿真工作.Max说他在没有正确舍入情况下实现了乘法和加法. 阅读全文
posted @ 2022-09-05 20:04 zjh6 阅读(12) 评论(0) 推荐(0) 编辑
摘要:原文 按值传递相当于浅(1级深)不等.遗憾的是,在当前语言中无法表示. struct A { int[] slice; } void main() { const a = A([1, 2, 3]); pass(a); // 仍有常 } void pass(Unqual!(const A) value 阅读全文
posted @ 2022-09-05 11:17 zjh6 阅读(6) 评论(0) 推荐(0) 编辑
摘要:原文 import std.exception; import std.stdio; abstract class B { B opCall() { throw new Exception("NotImplemented"); } } class A : B { override B opCall( 阅读全文
posted @ 2022-09-05 08:36 zjh6 阅读(14) 评论(0) 推荐(0) 编辑
摘要:原文 结构化并发库具有严格的任务所有权概念. 或用D现有的析构器规则 异步api,最好地复制窗口API.可回调和同步.这里 我在arsd.http2中使用了类似模型,调用返回请求函数,可附加回调等,然后发送它,然后在需要时等待响应对象.我非常喜欢它,即使没有完整事件循环,也可用它,它只是根据需要一步 阅读全文
posted @ 2022-09-04 23:10 zjh6 阅读(13) 评论(0) 推荐(0) 编辑
摘要:可以试试:这里方法 将文件夹设置在单独进程中打开. 阅读全文
posted @ 2022-09-04 10:55 zjh6 阅读(31) 评论(0) 推荐(0) 编辑
摘要:// 声明模板 template<class T> struct container { container(T t) {} template<class Iter> container(Iter beg, Iter end); }; // 附加推导 template<class Iter> con 阅读全文
posted @ 2022-09-03 20:49 zjh6 阅读(21) 评论(0) 推荐(0) 编辑
摘要:原文 struct biig { int[1024 * 1024] biig = 0; } biig biig; 你用的是哪个版本的dmd?我用2.098(旧的gitmaster)编译上面的代码,总的可执行文件大小只有900KB. 记得大概一两年前有一个bug,dmd会生成1024*1024存储指令 阅读全文
posted @ 2022-09-03 10:47 zjh6 阅读(18) 评论(0) 推荐(0) 编辑
摘要:原文 无间接的不变表达式不转换为可变. void main() { const i = 42; // 常,所以T应为常. foo(i); } void foo(T)(T value) { T result; ++result; // 编译错误,但是否应工作? } 我觉得它应可工作,因为"结果"是局部 阅读全文
posted @ 2022-09-03 09:53 zjh6 阅读(7) 评论(0) 推荐(0) 编辑
摘要:原文 struct Time { public int hours, minutes, seconds; this(int h, int m, int s) { hours = h; minutes = m; seconds = s; } Time opBinary(string op : "=") 阅读全文
posted @ 2022-09-03 09:19 zjh6 阅读(10) 评论(0) 推荐(0) 编辑
摘要:原文 import std.stdio; import std.string; import std.array; import std.range.primitives; string mwrite(string str) @safe pure { size_t istart; bool inwo 阅读全文
posted @ 2022-09-03 08:43 zjh6 阅读(24) 评论(0) 推荐(0) 编辑
摘要:原文 struct S(T, size_t memberCapacity = size_t.max) { static if (memberCapacity != size_t.max) { // 用户想要成员数组 T[memberCapacity] arr; void initMemberArra 阅读全文
posted @ 2022-09-02 14:32 zjh6 阅读(16) 评论(0) 推荐(0) 编辑
摘要:原文 对栈与16字节对齐的64位编译中,float8(AVX,32字节对齐)尤其如此.注意,理论上AVX也可以在32位中使用,但目前dmd既不公开内联内置函数也不公开YMM0-YMM7,因此不能在那里遇到这个问题. 据我所知,gcc,icc,llvm等主要编译器支持对齐正确堆栈对齐>=16的任何内容 阅读全文
posted @ 2022-09-01 15:39 zjh6 阅读(21) 评论(0) 推荐(0) 编辑
摘要:原文 auto assign(ref scope int* x, return ref int y) @safe { x = &y; } auto assign(ref scope int* x, return scope int* y) @safe { x = y; } y赋值给生命期更长的x 更 阅读全文
posted @ 2022-09-01 11:12 zjh6 阅读(24) 评论(0) 推荐(0) 编辑
摘要:按期望编译: int* f()(int* p) { static int g; g = 0; return new int; } int* g() @safe { int x; return f(&x); } 如下不是,但应该: int* f()(int* p) { static int g; g 阅读全文
posted @ 2022-09-01 11:05 zjh6 阅读(10) 评论(0) 推荐(0) 编辑
摘要:这里,看看,我们是cpp+lml类型. let s:cdy='"/* vim: set ft=cpp.lml : */"' 现在,我们是vim+lml类型. let s:lml='"/* vim: set ft=vim.lml : */"' 看看,是不是可以实现组合文件类型. 可以组合特定类型,来实 阅读全文
posted @ 2022-09-01 10:16 zjh6 阅读(14) 评论(0) 推荐(0) 编辑
摘要:假定,std.typecons.Tuple,可用[tup.expand]从元组造数组.[valSeq]搞值序列. 如下搞数组的数组: auto arrayOfArrays = [ keys, values ]; 更通用的: import std; //编译慢但是很方便 auto makeTestTu 阅读全文
posted @ 2022-09-01 09:29 zjh6 阅读(13) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示