fork download
  1. #include <iostream>
  2. #include <functional>
  3. using namespace std;
  4.  
  5. template <typename T, typename U, typename func>
  6. T halfmod(func f, T n, U mod){
  7. return f(n/2,mod);
  8. }
  9.  
  10. int main(){
  11. int n = 6262468, mod = 1000;
  12. auto f = [](int n, int mod){ return n%mod;} ;
  13. cout << f(n,mod) << endl; //should output 468, which it does
  14. cout << halfmod(f, n, mod) << endl; //should output 234... error
  15. return 0;
  16. }
  17.  
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
468
234