From 78efa932fb42289904fe542cfc152978397ae37c Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Tue, 15 Dec 2020 11:39:36 +0100 Subject: Fixing cpp07/ex00 with const& & and type only, Added more test in main for cpp07 --- cpp07/ex01/iter.hpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'cpp07/ex01/iter.hpp') diff --git a/cpp07/ex01/iter.hpp b/cpp07/ex01/iter.hpp index df1a37a..8118060 100644 --- a/cpp07/ex01/iter.hpp +++ b/cpp07/ex01/iter.hpp @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/14 15:06:48 by cacharle #+# #+# */ -/* Updated: 2020/12/14 15:18:09 by cacharle ### ########.fr */ +/* Updated: 2020/12/15 11:23:16 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,10 +22,43 @@ void iter(T* ptr, size_t len, void (*f)(T const& x)) f(ptr[i]); } +template +void iter(T* ptr, size_t len, void (*f)(T& x)) +{ + for (size_t i = 0; i < len; i++) + f(ptr[i]); +} + +template +void iter(T* ptr, size_t len, void (*f)(T x)) +{ + for (size_t i = 0; i < len; i++) + f(ptr[i]); +} + template void timeTwo(T const& x) { std::cout << "timeTwo function " << x << " * 2 = " << x * 2 << std::endl; } +template +void timeThree(T& x) +{ + std::cout << "timeThree function " << x << " * 3 = " << x * 3 << std::endl; +} + +class NotAnInt +{ +public: + NotAnInt(); + NotAnInt(int n); + NotAnInt(NotAnInt const& other); + NotAnInt& operator=(NotAnInt const& other); + int getN() const; + +private: + int m_n; +}; + #endif -- cgit