小编Naa*_*Met的帖子

"用D语言中的块"

withD语言的经典块吗?

我正在寻找以下行为:

struct Address {
  string street;
  int number;
}

struct Person {
  Address address;
}

// in some function
Person p = ...
with(p.address) {
  street = "Wide St.";
  number = 123;
}

// I am open to other solutions, if they could work e.g.
p.address.with => { street = ...; number = ...; }

assert(p.address.street == "Wide St.");
Run Code Online (Sandbox Code Playgroud)

如果它不可用,您将如何更新嵌套结构的几个字段?在C++中,我将嵌套分配给引用.

d with-statement

2
推荐指数
1
解决办法
139
查看次数

标签 统计

d ×1

with-statement ×1