摘要:        
d在简洁性和表达性方面,胜了很多.而rust的明确性更好.rust更学术,D更实用. module main; import std.stdio; void main() { writeln( "Hello, 世界" ); } fn main() { println!("Hello, 世界") }     阅读全文
        
            posted @ 2022-02-20 20:22
zjh6
阅读(75)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
原文 打开和关闭文件 import core.stdc.errno; import std.exception; import std.stdio; void main(string[] args) { try { auto file = File("test.txt", "r"); file.cl    阅读全文
        
            posted @ 2022-02-20 17:58
zjh6
阅读(20)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
原文 这样实现类似Qt中的信号和槽: class Foo : XObject { @signal void message( string str ); } class Bar : XObject { @slot void print( string str ) { writefln( "Bar.p    阅读全文
        
            posted @ 2022-02-20 16:27
zjh6
阅读(52)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
interface A { @property int data(); @property void data(int); } alias helper(alias T) = T; string implement(Interface)() { string code; import std.tra    阅读全文
        
            posted @ 2022-02-20 15:27
zjh6
阅读(35)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
原文 编译时反射使D元编程灵活而强大. 找出表达式的有效性: __traits( compiles, a + b ); is( typeof( a + b ) ); __traits(compiles,expr)和is(typeof(expr))都需要词法有效表达式.但后者不检查是否编译,而是检查是    阅读全文
        
            posted @ 2022-02-20 11:31
zjh6
阅读(18)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
原文 import std.range; static assert(isInputRange!(uint[])); // true static assert(isInputRange!string); // true static assert(!isInputRange!void); // f    阅读全文
        
            posted @ 2022-02-20 09:43
zjh6
阅读(16)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
原文 ref-return-scope易混淆. 现在规则改为: 除非return scope按源码出现的顺序(中域),否则ref-return-scope总是按ref-return scope理解. 可处理各种情况,为后向兼容,放在-preview=dip1000里面. 比如: ref int fo    阅读全文
        
            posted @ 2022-02-19 10:48
zjh6
阅读(17)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
下面应在dip1000下编译失败. ref int test(ref scope return int* p) { return *p; } p应为return ref与scope,但编译器按ref/return scope解释并通过. 问题是,返回了p的值,而return ref/scope应阻止    阅读全文
        
            posted @ 2022-02-19 10:38
zjh6
阅读(14)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
原文 我想在B定义中使用A而不是串 struct A { string s; this (string s) { this.s = s; } } struct B { A a; A b; } void main () { auto b0 = B (A ("A"), A ("B")); // 工作,但    阅读全文
        
            posted @ 2022-02-19 10:26
zjh6
阅读(23)
评论(0)
推荐(0)
        
        
            
        
        
摘要:        
原文 纯函数可通过异常逃逸参数 修复阻止了通过返回值逃逸,但还有限制:即使无法通过参数或返回值逃逸,仍可把纯函数参数放入异常并抛. void f_throw(string x) @safe pure { throw new Exception(x); }//异常. void escape_throw    阅读全文
        
            posted @ 2022-02-18 10:36
zjh6
阅读(14)
评论(0)
推荐(0)
        
        
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号