fork download
  1. #include <iostream>
  2.  
  3. template<typename T, T const array[], int I>
  4. struct Indexer
  5. {
  6. static const T value = array[I];
  7. };
  8.  
  9. constexpr int foo[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  10.  
  11. enum Bar
  12. {
  13. value1 = Indexer<int, foo, 1>::value,
  14. value3 = Indexer<int, foo, 3>::value,
  15. value7 = Indexer<int, foo, 7>::value,
  16. };
  17.  
  18. int main()
  19. {
  20. std::cout << Bar::value3 << std::endl;
  21. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
3