입력 및 대상으로 정확하게 짝을 지어야하는 데이터 요소를 보유하고있는 사용자 지정 컨테이너에서 반복 할 입력 범위를 만들고 있습니다. 훈련 데이터 (double [] []), 입력 (double []) 및 대상 (double [])을 반환하기 위해 다른 범위가 필요합니다. 나는 다음 코드를 컴파일하고 완벽하게 처리 할 수 있었지만 그 이유는 모른다.구조 표현식 매개 변수 대 형식 매개 변수
public struct DataRange(string type)
if(type == "TrainingData" ||
type == "InputData" ||
type == "TargetData")
{
private immutable(int) length;
private uint next;
private Data data;
this(Data d){
this.length = d.numPoints;
this.next = 0;
this.data = d;
}
@property bool empty(){return next == length;}
@property auto front(){
static if(type == "TrainingData")
return this.data.getTrainingData(next);
else static if(type == "InputData")
return this.data.getInputData(next);
else return this.data.getTargetData(next);
}
void popFront(){++next;}
}
static assert(isInputRange!(DataRange!"TrainingData"));
static assert(isInputRange!(DataRange!"InputData"));
static assert(isInputRange!(DataRange!"TargetData"));
내가 Alexandrescu에 의해는 "D 프로그래밍 언어"를 읽어 봤는데
, 나는 형태
struct S(T){...} // or
struct S(T[]){...}
하지만, 이러한 유형의 매개 변수가 아닌 표현 나는 것 같은을의 매개 변수 구조체를 발견했다 끝난. 매개 변수가있는 유형이있는 dlang.org에서 유사한 예제를 찾을 수 없었습니다.
이 내용은 DMD 2.066 및 GDC 4.9.0에서 컴파일되고 작동합니다.
나는 왜 이것을 시도했는지, 그리고 그것을 뒤돌아 보면 나는 그것이 왜 작동 하는지를 모른다. 아무도 내가 누락 된 걸 압니까? 이 문서는 어디에 문서화되어 있습니까?
온라인에서 사용할 수있는 D의 템플릿에 대한 유용한 책/가이드가 있습니다. https://github.com/PhilippeSigaud/D-templates-tutorial. 때로 언어 문서보다 더 잘 설명 할 수 있습니다. – yaz