diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-12-15 11:39:36 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-12-15 11:39:36 +0100 |
| commit | 78efa932fb42289904fe542cfc152978397ae37c (patch) | |
| tree | 6878dc28e015f570aa6951f1d781115551d03997 /cpp07/ex01/iter.hpp | |
| parent | 1de596dd9242b677d6b47b51db98ce98feb95465 (diff) | |
| download | piscine_cpp-78efa932fb42289904fe542cfc152978397ae37c.tar.gz piscine_cpp-78efa932fb42289904fe542cfc152978397ae37c.tar.bz2 piscine_cpp-78efa932fb42289904fe542cfc152978397ae37c.zip | |
Fixing cpp07/ex00 with const& & and type only, Added more test in main for cpp07
Diffstat (limited to 'cpp07/ex01/iter.hpp')
| -rw-r--r-- | cpp07/ex01/iter.hpp | 35 |
1 files changed, 34 insertions, 1 deletions
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 <me@cacharle.xyz> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ @@ -23,9 +23,42 @@ void iter(T* ptr, size_t len, void (*f)(T const& x)) } template<typename T> +void iter(T* ptr, size_t len, void (*f)(T& x)) +{ + for (size_t i = 0; i < len; i++) + f(ptr[i]); +} + +template<typename T> +void iter(T* ptr, size_t len, void (*f)(T x)) +{ + for (size_t i = 0; i < len; i++) + f(ptr[i]); +} + +template<typename T> void timeTwo(T const& x) { std::cout << "timeTwo function " << x << " * 2 = " << x * 2 << std::endl; } +template<typename T> +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 |
