摘要:        
文档: import std.algorithm.comparison : equal; import std.conv : to; alias stringize = map!(to!string); assert(equal(stringize([ 1, 2, 3, 4 ]), [ "1", "    阅读全文
        
            posted @ 2022-02-22 10:00
zjh6
阅读(31)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
原文 import std.sumtype; struct Unit {} alias Option(T) = SumType!(T, Unit); //不能推导别名. void foobar(T)(Option!T option) {} void main() { foobar(Option!in    阅读全文
        
            posted @ 2022-02-22 09:55
zjh6
阅读(15)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
原文 用StdioException抛为何不能不抛? nothrow void hello() { try { writeln("Hello, World!") } catch (StdioException) {} } 这却可以? nothrow void hello() { try { writ    阅读全文
        
            posted @ 2022-02-21 19:35
zjh6
阅读(17)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
原文 import std.stdio; // 最先,需要函数指针. T[] map_vals(T,S)(scope T function(S) f, S[] a){ auto b = new T[a.length]; foreach(i,x;a) b[i] = f(x); return b; }     阅读全文
        
            posted @ 2022-02-21 19:24
zjh6
阅读(23)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
概述 程序的内存安全性取决于程序员和语言实现维护程序数据运行时不变量的能力. D编译器知道内置类型(如数组和指针)的运行时不变量,并且可用编译时检查来确保正确.这些检查对用户定义类型并不总是足够的.为了可靠维护编译器硬编码知识之外的不变量,D程序员必须求助于手动验证@safe代码和防御性的运行时检查    阅读全文
        
            posted @ 2022-02-21 15:47
zjh6
阅读(21)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
析构器的目的是描述对象生命期结束时的清理工作.允许@safe代码在该点前手动调用析构器,然后继续用析构对象会破坏RAII内存管理: module app; import core.stdc.stdlib : malloc, free; struct UniqueInt { private int*     阅读全文
        
            posted @ 2022-02-21 09:51
zjh6
阅读(17)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
规范显示按域声明闭包,但编译器不强制. struct S { int opApply (/*scope*/ int delegate (int* ptr) @safe dg) @safe { return 0; }//无域. } void test(S s) @safe { foreach (int    阅读全文
        
            posted @ 2022-02-21 09:29
zjh6
阅读(76)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
原文 import std.conv; class Foo { int i; // v 推导类型 this(int)//(T i) { this.i = i;//.to!int; } string test() { return i.to!string; } } void main() { long    阅读全文
        
            posted @ 2022-02-21 09:15
zjh6
阅读(17)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
原文 基于opDispatch+__traits(getMember)的库解决方案. template FieldOfKeyword(string[2][] keywordFieldPairs) { template opDispatch(string member) { static foreac    阅读全文
        
            posted @ 2022-02-20 22:10
zjh6
阅读(16)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
原文下 取类型大小(字节) int.sizeof (char*).sizeof double.sizeof Foo.sizeof //Rust size_of::<i32>() size_of::<*const i8>() size_of::<f64>() size_of::<Foo>() let     阅读全文
        
            posted @ 2022-02-20 20:22
zjh6
阅读(17)
评论(0)
推荐(0)
        
        
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号