// File: /workspace/github_cpp_makefile_star2_O2/amukherj[P]concurrencyts/./future.h
// Function: concurrencyts::future<std::vector<std::iterator_traits<__gnu_cxx::__normal_iterator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>*, std::vector<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>>::value_type, std::allocator<std::iterator_traits<__gnu_cxx::__normal_iterator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>*, std::vector<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>>::value_type>>> concurrencyts::when_all<__gnu_cxx::__normal_iterator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>*, std::vector<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>>(__gnu_cxx::__normal_iterator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>*, std::vector<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>, __gnu_cxx::__normal_iterator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>*, std::vector<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<concurrencyts::future<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>)
auto when_all(InputIt begin, InputIt end)
  -> future<std::vector<typename std::iterator_traits<InputIt>::value_type>> {
  using ret_type = typename std::iterator_traits<InputIt>::value_type;
  promise<std::vector<ret_type>> prom;
  auto fut = prom.get_future();

  if (begin != end) {
    begin->wait();
    (begin + 1)->wait();
  }

  std::thread t([begin, end](promise<std::vector<ret_type>> prom) {
    try {
      std::vector<ret_type> result;
      begin->wait();
      (begin + 1)->wait();
      for (auto it = begin; it != end; ++it) {
        it->wait();
        result.emplace_back(std::move(*it));
      }
      prom.set(std::move(result));
      std::this_thread::sleep_for(std::chrono::seconds(5));
    } catch(std::exception& e) {
      prom.set_exception(e);
    }
  }, std::move(prom));
  t.detach();

  return fut;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x66a1
movq %rbx, %rdi
movq %r12, %rsi
callq 0x65da
cmpq %r14, %r15
je 0x564f
movq %r15, %rdi
callq 0x6612
leaq 0x10(%r15), %rdi
callq 0x6612
leaq 0x18(%rsp), %rsi
movq %r15, (%rsi)
movq %r14, 0x8(%rsi)
movq %rsp, %rdi
leaq 0x8(%rsp), %rdx
callq 0x661a
movq %rsp, %rdi
callq 0x3290
movq %rsp, %rdi
callq 0x55a8
leaq 0x10(%rsp), %rdi
callq 0x594e
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0x56a2
jmp 0x56a2
movq %rax, %r14
movq %rsp, %rdi
callq 0x55a8
jmp 0x56a5
movq %rax, %r14
addq $0x8, %rbx
movq %rbx, %rdi
callq 0x594e
jmp 0x56b6
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x594e
movq %r14, %rdi
callq 0x32a0