fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <utility>
  4. #include <array>
  5.  
  6. using namespace std;
  7.  
  8. template <int p>
  9. double power(double val) {
  10. return pow(val,p);
  11. }
  12.  
  13. template <size_t ...powers>
  14. constexpr auto make_power_funcs(index_sequence<powers...>) {
  15. array<double(*)(double),256> arr = { &power<powers>... };
  16. return arr;
  17. }
  18.  
  19. constexpr auto power_funcs = make_power_funcs(make_index_sequence<256>());
  20.  
  21. int main ()
  22. {
  23. cout << power_funcs[2](5) << endl;
  24. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
25