fork download
  1. #include <iostream>
  2. #include <functional>
  3. using namespace std;
  4.  
  5. void LowPassFilter(float *samples,int size,function<float(int)> cutoffProducer)
  6. {
  7. for(int i=0;i<size;i++)
  8. {
  9. cout << "For sample " << i << " cutoff is " << cutoffProducer(i) << endl;
  10. }
  11. }
  12.  
  13. std::function<float(int)> Const(float cutoff)
  14. {
  15. return [=](int) { return cutoff; };
  16. }
  17.  
  18. std::function<float(int)> Linear(float coefficient)
  19. {
  20. return [=](int i) { return coefficient * i; };
  21. }
  22.  
  23. int main() {
  24. LowPassFilter(0, 10, Const(42));
  25. LowPassFilter(0, 10, Linear(.5));
  26. return 0;
  27. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
For sample 0 cutoff is 42
For sample 1 cutoff is 42
For sample 2 cutoff is 42
For sample 3 cutoff is 42
For sample 4 cutoff is 42
For sample 5 cutoff is 42
For sample 6 cutoff is 42
For sample 7 cutoff is 42
For sample 8 cutoff is 42
For sample 9 cutoff is 42
For sample 0 cutoff is 0
For sample 1 cutoff is 0.5
For sample 2 cutoff is 1
For sample 3 cutoff is 1.5
For sample 4 cutoff is 2
For sample 5 cutoff is 2.5
For sample 6 cutoff is 3
For sample 7 cutoff is 3.5
For sample 8 cutoff is 4
For sample 9 cutoff is 4.5