fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. constexpr unsigned long long factorial(unsigned long long n) {
  5. return (n <= 1 ? 1 : n*factorial(n-1));
  6. }
  7.  
  8. int main() {
  9.  
  10. // universal initialization
  11. std::vector<int> v{1,2,3,4,5,6};
  12.  
  13. // move semantics
  14. std::vector<int> v2(std::move(v));
  15.  
  16. // for each loop and auto
  17. for(auto e: v2) {
  18. std::cout << e << '\n';
  19. }
  20.  
  21. // static assert makes assertions at compile-time
  22. static_assert(factorial(5) == 120, "factorial(5) should be 120.");
  23. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
1
2
3
4
5
6