D Language
컴파일 시간 기능 평가 (CTFE)
수색…
비고
CTFE는 컴파일러가 컴파일 할 때 함수를 실행할 수있게하는 메커니즘입니다. 이 기능을 사용하는 데 필요한 특별한 D 언어는 없습니다. 컴파일시 D 컴파일러가 컴파일 중에 해석 할 수있는 알려진 값을 컴파일 타임에만 의존 할 때마다 말이죠.
컴파일 타임에 함수를 평가하십시오.
long fib(long n)
{
return n < 2 ? n : fib(n - 1) + fib(n - 2);
}
struct FibStruct(int n) { // Remarks: n is a template
ubyte[fib(n)] data;
}
void main()
{
import std.stdio : writeln;
enum f10 = fib(10); // execute the function at compile-time
pragma(msg, f10); // will print 55 during compile-time
writeln(f10); // print 55 during runtime
pragma(msg, FibStruct!11.sizeof); // The size of the struct is 89
}
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow