2014-06-10 8 views
2

with 블록은 D 언어로 제공됩니까?D 언어로 된 "With"블록

나는 다음과 같은 동작을 찾고 있어요 : 그것은 사용할 수없는 경우

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."); 

, 어떻게 중첩 된 구조체의 여러 필드를 업데이트 할 것인가? C++에서는 중첩 된 참조를 참조로 지정했습니다.

답변