Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. EX00:
  2. #include <iostream>
  3. #include <string>
  4. #include "ex00.hpp"
  5. int main()
  6. {
  7. int a = 2;
  8. int b = 3;
  9.  
  10. ::swap(a, b);
  11. std::cout << "a = " << a << ", b = " << b << std::endl;
  12. std::cout << "min(a, b) = " << ::min(a, b) << std::endl;
  13. std::cout << "max(a, b) = " << ::max(a, b) << std::endl;
  14. std::cout << "add(a, b) = " << ::add(a, b) << std::endl;
  15. std::string c = "chaine1";
  16. std::string d = "chaine2";
  17. ::swap(c, d);
  18. std::cout << "c = " << c << ", d = " << d << std::endl;
  19. std::cout << "min(c, d) = " << ::min(c, d) << std::endl;
  20. std::cout << "max(c, d) = " << ::max(c, d) << std::endl;
  21. std::cout << "add(c, d) = " << ::add(c, d) << std::endl;
  22. }
  23.  
  24. <---------------------------------------------------------------------------->
  25.  
  26. EX01:
  27. #include <iostream>
  28. #include "ex01.hpp"
  29.  
  30. class toto
  31. {
  32. private:
  33. toto &operator=(const toto&) {return *this;}
  34. toto(const toto &){}
  35. public:
  36. bool operator==(const toto&) const {return true;}
  37. bool operator>(const toto&) const {return false;}
  38. bool operator<(const toto&) const {return false;}
  39. toto(){}
  40. };
  41.  
  42. int main()
  43. {
  44. toto a, b;
  45.  
  46. std::cout << compare(a, b) << " = 0" << std::endl;
  47. std::cout << compare(1, 2) << " = -1" << std::endl;
  48. std::cout << compare<const char*>("chaineZ", "chaineA42") << " = 1" << std::endl;
  49. const char *s1 = "42", *s2 = "lulz";
  50. std::cout << compare(s1, s2) << " = -1" << std::endl;
  51. }
  52.  
  53. <---------------------------------------------------------------------------->
  54.  
  55. EX02:
  56. #include <iostream>
  57. #include "ex02.hpp"
  58.  
  59. int main()
  60. {
  61. int tab[2] = {3, 0};
  62. int minimum = templateMin(tab, 2);
  63. std::cout << "templateMin(tab, 2) = " << minimum << std::endl;
  64. minimum = nonTemplateMin(tab, 2);
  65. std::cout << "nonTemplateMin(tab, 2) = " << minimum << std::endl;
  66. }
  67.  
  68. <---------------------------------------------------------------------------->
  69.  
  70. EX03:
  71. #include <iostream>
  72. #include "ex03.hpp"
  73.  
  74. int main()
  75. {
  76. int tab[] = { 11, 3, 89, 42 };
  77. foreach(tab, print<int>, 4);
  78. std::string tab2[] = { "jā€™", "aime", "les", "templates", "!" };
  79. foreach(tab2, print, 5);
  80. return 0;
  81. }
  82.  
  83. <---------------------------------------------------------------------------->
  84.  
  85. EX04:
  86. #include <iostream>
  87. #include "ex04.hpp"
  88.  
  89. int main()
  90. {
  91. std::cout << "1 == 0 ? " << equal(1, 0) << std::endl;
  92. std::cout << "1 == 1 ? " << equal(1, 1) << std::endl;
  93. Tester<int> iT;
  94. std::cout << "41 == 42 ? " << iT.equal(41, 42) << std::endl;
  95. std::cout << "42 == 42 ? " << iT.equal(42, 42) << std::endl;
  96. return 0;
  97. }
  98.  
  99. <---------------------------------------------------------------------------->
  100.  
  101. EX05:
  102. #include <iostream>
  103. #include "ex05.hpp"
  104.  
  105. int float_to_int(float const& f)
  106. {
  107. return static_cast<int>(f);
  108. }
  109.  
  110. int main()
  111. {
  112. array<int> a(4);
  113. a[3] = 1;
  114. const array<int> b = a;
  115. b.dump();
  116. array<float> c;
  117. c.dump();
  118. c[2] = 1.1;
  119. c.dump();
  120. a = c.convertTo<int>(&float_to_int);
  121. a.dump();
  122. }
  123.  
  124. <---------------------------------------------------------------------------->
  125.  
  126. EX06:
  127. #include <iostream>
  128. #include "ex06.hpp"
  129.  
  130. void test1()
  131. {
  132. Tuple<int, std::string> t;
  133. t.a = 42;
  134. t.b = std::string("Boeuf aux oignons");
  135. std::cout << t.toString() << std::endl;
  136. }
  137.  
  138. void test2()
  139. {
  140. Tuple<float, char> t;
  141. t.a = 1.1f;
  142. t.b = 'x';
  143. std::cout << t.toString() << std::endl;
  144. }
  145.  
  146. int main()
  147. {
  148. test1();
  149. test2();
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement