How can I pass std function as a function's parameter?

Правка en1, от aldol_reaction, 2021-08-12 15:09:17

include <bits/stdc++.h>

using namespace std; int Min(int a, int b) {return a < b ? a : b;}

template<class T,int N,T (*fun)(T,T)> struct SparseTable{ int lg[N+10],n; T f[21][N+10]; int pw(int x){return 1<<x;} SparseTable():n(0){lg[0]=-1;} void insert(T x){ f[0][++n]=x,lg[n]=lg[n>>1]+1; for(int t=1;pw(t)<=n;t++){ int i=n-pw(t)+1; f[t][i]=fun(f[t-1][i],f[t-1][i+pw(t-1)]); } } T query(int l,int r){ int len=lg[r-l+1]; return fun(f[len][l],f[len][r-pw(len)+1]); } };

int main() { SparseTable<int,100010, Min> t;//compile succussfully // SparseTable<int,100010, min> t;//compile failed return 0; }

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский aldol_reaction 2021-08-12 15:10:09 13
en1 Английский aldol_reaction 2021-08-12 15:09:17 787 Initial revision (published)