Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EX00:
- #include <iostream>
- #include <string>
- #include "ex00.hpp"
- int main()
- {
- int a = 2;
- int b = 3;
- ::swap(a, b);
- std::cout << "a = " << a << ", b = " << b << std::endl;
- std::cout << "min(a, b) = " << ::min(a, b) << std::endl;
- std::cout << "max(a, b) = " << ::max(a, b) << std::endl;
- std::cout << "add(a, b) = " << ::add(a, b) << std::endl;
- std::string c = "chaine1";
- std::string d = "chaine2";
- ::swap(c, d);
- std::cout << "c = " << c << ", d = " << d << std::endl;
- std::cout << "min(c, d) = " << ::min(c, d) << std::endl;
- std::cout << "max(c, d) = " << ::max(c, d) << std::endl;
- std::cout << "add(c, d) = " << ::add(c, d) << std::endl;
- }
- <---------------------------------------------------------------------------->
- EX01:
- #include <iostream>
- #include "ex01.hpp"
- class toto
- {
- private:
- toto &operator=(const toto&) {return *this;}
- toto(const toto &){}
- public:
- bool operator==(const toto&) const {return true;}
- bool operator>(const toto&) const {return false;}
- bool operator<(const toto&) const {return false;}
- toto(){}
- };
- int main()
- {
- toto a, b;
- std::cout << compare(a, b) << " = 0" << std::endl;
- std::cout << compare(1, 2) << " = -1" << std::endl;
- std::cout << compare<const char*>("chaineZ", "chaineA42") << " = 1" << std::endl;
- const char *s1 = "42", *s2 = "lulz";
- std::cout << compare(s1, s2) << " = -1" << std::endl;
- }
- <---------------------------------------------------------------------------->
- EX02:
- #include <iostream>
- #include "ex02.hpp"
- int main()
- {
- int tab[2] = {3, 0};
- int minimum = templateMin(tab, 2);
- std::cout << "templateMin(tab, 2) = " << minimum << std::endl;
- minimum = nonTemplateMin(tab, 2);
- std::cout << "nonTemplateMin(tab, 2) = " << minimum << std::endl;
- }
- <---------------------------------------------------------------------------->
- EX03:
- #include <iostream>
- #include "ex03.hpp"
- int main()
- {
- int tab[] = { 11, 3, 89, 42 };
- foreach(tab, print<int>, 4);
- std::string tab2[] = { "jā", "aime", "les", "templates", "!" };
- foreach(tab2, print, 5);
- return 0;
- }
- <---------------------------------------------------------------------------->
- EX04:
- #include <iostream>
- #include "ex04.hpp"
- int main()
- {
- std::cout << "1 == 0 ? " << equal(1, 0) << std::endl;
- std::cout << "1 == 1 ? " << equal(1, 1) << std::endl;
- Tester<int> iT;
- std::cout << "41 == 42 ? " << iT.equal(41, 42) << std::endl;
- std::cout << "42 == 42 ? " << iT.equal(42, 42) << std::endl;
- return 0;
- }
- <---------------------------------------------------------------------------->
- EX05:
- #include <iostream>
- #include "ex05.hpp"
- int float_to_int(float const& f)
- {
- return static_cast<int>(f);
- }
- int main()
- {
- array<int> a(4);
- a[3] = 1;
- const array<int> b = a;
- b.dump();
- array<float> c;
- c.dump();
- c[2] = 1.1;
- c.dump();
- a = c.convertTo<int>(&float_to_int);
- a.dump();
- }
- <---------------------------------------------------------------------------->
- EX06:
- #include <iostream>
- #include "ex06.hpp"
- void test1()
- {
- Tuple<int, std::string> t;
- t.a = 42;
- t.b = std::string("Boeuf aux oignons");
- std::cout << t.toString() << std::endl;
- }
- void test2()
- {
- Tuple<float, char> t;
- t.a = 1.1f;
- t.b = 'x';
- std::cout << t.toString() << std::endl;
- }
- int main()
- {
- test1();
- test2();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement