在这个页面中,我找到了一个新的JavaScript函数类型:
// NOTE: "function*" is not supported yet in Firefox.
// Remove the asterisk in order for this code to work in Firefox 13
function* fibonacci() { // !!! this is the interesting line !!!
let [prev, curr] = [0, 1];
for (;;) {
[prev, curr] = [curr, prev + curr];
yield curr;
}
}
Run Code Online (Sandbox Code Playgroud)
我已经知道了什么yield,let以及[?,?]=[?,?]做的,但不知道什么function*是注定的.它是什么?
我正在尝试实现泛型类.它应该有一个属性,该属性需要一个编译时常量,我想将其设置为参数类型的名称.像这样的东西:
namespace Example
{
public class MyGeneric<T>
{
[SomeAttribute(CompileTimeConstant)]
public int MyProperty { get; set; }
private const string CompileTimeConstant = typeof(T).Name; // error CS0133:
// The expression being assigned to `Example.MyGeneric<T>.CompileTimeConstant' must be constant
}
}
Run Code Online (Sandbox Code Playgroud)
但是因为typeof(T).Name在运行时进行评估,所以它不起作用.可能吗?
代码
#include <iostream>
using namespace std;
template<int n> struct Fibo { static int x; };
template<> int Fibo<0>::x = 1;
template<> int Fibo<1>::x = 1;
template<int n> int Fibo<n>::x = Fibo<n-1>::x + Fibo<n-2>::x; //marked line
int main() {
cout << Fibo<5>::x << endl;
cout << Fibo<4>::x << endl;
cout << Fibo<3>::x << endl;
cout << Fibo<2>::x << endl;
cout << Fibo<1>::x << endl;
cout << Fibo<0>::x << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出
0
0
1
2
1
1
Run Code Online (Sandbox Code Playgroud)
在VC++中.(根据用户M …
是否可以在SQL Server 2008中的不同数据库中定义表之间的关系?你能推荐一个在线教程来研究吗?(我更喜欢ASP.NET,C#)
c# ×1
c++ ×1
compile-time ×1
database ×1
ecmascript-6 ×1
function ×1
generics ×1
javascript ×1
recursion ×1
reflection ×1
relationship ×1
sql-server ×1
templates ×1
visual-c++ ×1