fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iterator>
  5. #include <deque>
  6. #include <functional>
  7.  
  8. #define BEGIN_TO_END(container) container.begin(), container.end()
  9.  
  10. template <template<typename...> class OutputContainerType, class InContainer>
  11. OutputContainerType<typename InContainer::value_type, std::allocator<typename InContainer::value_type>> convertContainer(const InContainer& in)
  12. {
  13. OutputContainerType<typename InContainer::value_type, std::allocator<typename InContainer::value_type>> result;
  14. std::transform(BEGIN_TO_END(in), std::back_inserter(result), [](typename InContainer::value_type value) {return value;});
  15. return result;
  16. }
  17.  
  18. int main() {
  19. std::deque<int> d {1, 2, 3};
  20. const auto v = convertContainer<std::vector>(d);
  21. std::cout << v.size() << std::endl;
  22. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
3