serial.tpp 573 B

12345678910111213141516171819202122232425
  1. //
  2. // serial.tpp
  3. // danmaku
  4. //
  5. // Created by Sam Jaffe on 5/27/19.
  6. // Copyright © 2019 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <json/json.h>
  10. #include <vector>
  11. namespace danmaku {
  12. template <typename F, typename... Args>
  13. auto to_vector(Json::Value const & json, F && func, Args &&... args)
  14. -> std::vector<decltype(func(json, args...))> {
  15. std::vector<decltype(func(json, args...))> out;
  16. out.reserve(json.size());
  17. for (int i = 0; i < json.size(); ++i) {
  18. out.emplace_back(func(json[i], args...));
  19. }
  20. return out;
  21. }
  22. }