Tainel

src/base/features/input.hpp

May 25th, 2023 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | Source Code | 0 0
  1. #pragma once
  2.  
  3. #include"base/dependencies/index.hpp"
  4.  
  5. #include"shortcuts.hpp"
  6.  
  7. // Read the given arguments in order from the given input stream.
  8. template<class...Types>
  9. istream&read(istream&is,Types&...args){return(is>>...>>args);}
  10.  
  11. // Pair input overload.
  12. template<class Fst,class Snd>
  13. istream&operator>>(istream&is,pair<Fst,Snd>&p){return is>>p.first>>p.second;}
  14.  
  15. // Tuple input overload.
  16. template<class...Types>istream&operator>>(istream&is,tuple<Types...>&t){
  17.     apply([&is](Types&...args){read(is,args...);},t);
  18.     return is;
  19. }
  20.  
  21. // Array input overload.
  22. template<class Type,size_t Size>
  23. istream&operator>>(istream&is,array<Type,Size>&a){
  24.     FORIT(it,a){is>>*it;}
  25.     return is;
  26. }
  27.  
  28. // Valarray input overload.
  29. template<class Type>istream&operator>>(istream&is,valarray<Type>&va){
  30.     FORIT(it,va){is>>*it;}
  31.     return is;
  32. }
  33.  
  34. // Vector input overload.
  35. template<class Type>istream&operator>>(istream&is,vector<Type>&v){
  36.     FORIT(it,v){
  37.         Type e;
  38.         is>>e,*it=move(e);
  39.     }
  40.     return is;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment