我創建了一個類來實現Atkin的Sieve以查找素數。該類存儲結果並提供「isPrime」方法。我還想添加一個允許您迭代素數的範圍。我在想是這樣的:將成員函數作爲模板參數傳入D
@property auto iter() { return filter!(this.isPrime)(iota(2, max, 1)); }
不幸的是,這並不工作:
Error: function primes.primes.isPrime (ulong i) is not callable using argument types()
Error: expected 1 function arguments, not 0
沒有「這個」我得到
Error: this for isPrime needs to be type primes not type Result
有沒有辦法通過一個成員函數作爲模板參數?
太棒了!謝謝。 – 2012-01-19 04:17:50