fork(1) download
  1. #include <iostream>
  2.  
  3. struct A { int x; constexpr A(int i) noexcept : x{i} {} };
  4. struct B { A a; constexpr B(A a) noexcept : a{a} {} };
  5.  
  6. constexpr int foo() {
  7. B b{55};
  8. return b.a.x;
  9. }
  10.  
  11. template<int N>
  12. void output()
  13. {
  14. std::cout << N << std::endl;
  15. }
  16.  
  17. int main() {
  18. // to be absolutely sure compile time eval'd,
  19. // pass as template arg
  20. constexpr auto b = foo();
  21. output<b>();
  22. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
55