D Language
संकलन समय फ़ंक्शन मूल्यांकन (CTFE)
खोज…
टिप्पणियों
CTFE एक ऐसा तंत्र है जो कंपाइलर को कंपाइल समय पर फंक्शन्स को निष्पादित करने की अनुमति देता है। इस सुविधा का उपयोग करने के लिए आवश्यक डी भाषा का कोई विशेष सेट नहीं है - जब भी कोई फ़ंक्शन बस संकलन समय ज्ञात मूल्यों पर निर्भर करता है तो डी कंपाइलर संकलन के दौरान इसकी व्याख्या करने का निर्णय ले सकता है।
आप CTFE के साथ अंतःक्रियात्मक रूप से भी खेल सकते हैं।
संकलन-समय पर एक फ़ंक्शन का मूल्यांकन करें
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