fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <int a>
  5. class foo
  6. {
  7. public:
  8. int n;
  9. constexpr foo() : n(a) { }
  10. };
  11.  
  12. template <int a>
  13. class foo2
  14. {
  15. public:
  16. static constexpr int n = a;
  17. };
  18.  
  19. template <size_t N>
  20. constexpr int simple_checksum(const char (&str)[N], int index = 0)
  21. {
  22. return (str[index] ? str[index] + simple_checksum(str, index+1) : 0);
  23. }
  24.  
  25. int main() {
  26. foo<simple_checksum("ala ma kota")> a;
  27. cout << "checksum: " << a.n << endl;
  28. cout << "checksum 2: " << foo2<simple_checksum("ala ma kota")>::n << endl;
  29. return 0;
  30. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
checksum: 1003
checksum 2: 1003