fork(2) download
  1. #include <iostream>
  2. #include <array>
  3. using namespace std;
  4. constexpr int N = 1e1;
  5. constexpr int f(int x) { return x*2; }
  6. typedef array<int, N> A;
  7. template<int... i> struct F { static constexpr A f() { return A{{ ::f(i)... }}; } };
  8. template<class A, class B> struct C {};
  9. template<int... i, int... j> struct C<F<i...>, F<j...>> : F<i..., (sizeof...(i)+j)...> { using T = F<i..., (sizeof...(i)+j)...>; };
  10. template<int n> struct S : C<typename S<n/2>::T, typename S<n-n/2>::T> {};
  11. template<> struct S<1> : F<0> { using T = F<0>; };
  12. constexpr auto X = S<N>::f();
  13. int main() { cout << X[3] << endl; }
Success #stdin #stdout 0s 3344KB
stdin
Standard input is empty
stdout
6