Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template< typename T = double> struct Box;
  5. template <typename T, int size > struct Arr;
  6.  
  7. template<>
  8. struct Box<>{
  9. double val;
  10. Box(double v): val(v){}
  11. friend std::ostream& operator<<(std::ostream& o, const Box<double>& b){
  12. return o <<b.val;}
  13. };
  14.  
  15. template<>
  16. struct Box<int>{
  17. int val;
  18. Box(int v): val(v){}
  19. friend std::ostream& operator<<(std::ostream& o, const Box<int>& b){
  20. return o<<b.val;}
  21. };
  22.  
  23. template <typename T, int size>
  24. struct Arr{
  25. int arr[size];
  26. int count = 0;
  27. Arr(){
  28. for (int i=1; i<=size; i++){
  29. arr[i-1] = i;
  30. }
  31. }
  32. int* begin(){return *arr;}
  33. int* end(){return *(arr+size);}
  34. std::ostream& operator<<(std::ostream& s, const Arr<int>& a){
  35. s<<a.arr[count];
  36. a.count++;
  37. return s;
  38. }
  39.  
  40. };
  41.  
  42. using make_Box = Box<>;
  43.  
  44. int main(){
  45. std::cout<< Box<int>(26.02) << std::endl; //wypisuje typ Box<int>
  46. std::cout<< make_Box(26.02) <<std::endl; //wypisuje typ Box<...>
  47. for (auto _ : Arr<<Box<int>,5>()){
  48. std::cout<< _ << ", " <<std::endl;}
  49. }
  50. /*output:
  51. 26
  52. 26.02
  53. 1, 2, 3, 4, 5,
  54. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement