diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-12-14 15:30:28 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-12-14 15:30:28 +0100 |
| commit | 1de596dd9242b677d6b47b51db98ce98feb95465 (patch) | |
| tree | acbc79883c0af843b8b999a39f96cefd48e6e390 /cpp07/ex01 | |
| parent | b13cd117a7957f9d86ec2986b47349979325a854 (diff) | |
| download | piscine_cpp-1de596dd9242b677d6b47b51db98ce98feb95465.tar.gz piscine_cpp-1de596dd9242b677d6b47b51db98ce98feb95465.tar.bz2 piscine_cpp-1de596dd9242b677d6b47b51db98ce98feb95465.zip | |
Updated cpp07 files with new subject
Diffstat (limited to 'cpp07/ex01')
| -rw-r--r-- | cpp07/ex01/Makefile | 4 | ||||
| -rw-r--r-- | cpp07/ex01/iter.hpp | 31 | ||||
| -rw-r--r-- | cpp07/ex01/main.cpp (renamed from cpp07/ex01/iter.cpp) | 30 |
3 files changed, 38 insertions, 27 deletions
diff --git a/cpp07/ex01/Makefile b/cpp07/ex01/Makefile index 45180bc..7bee119 100644 --- a/cpp07/ex01/Makefile +++ b/cpp07/ex01/Makefile @@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/04/14 19:48:34 by charles #+# #+# # -# Updated: 2020/04/14 20:02:14 by charles ### ########.fr # +# Updated: 2020/12/14 15:07:28 by cacharle ### ########.fr # # # # **************************************************************************** # @@ -15,7 +15,7 @@ NAME = iter CXX = clang++ CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -SRC = iter.cpp +SRC = main.cpp OBJ = $(SRC:.cpp=.o) all: $(NAME) diff --git a/cpp07/ex01/iter.hpp b/cpp07/ex01/iter.hpp new file mode 100644 index 0000000..df1a37a --- /dev/null +++ b/cpp07/ex01/iter.hpp @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* iter.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/12/14 15:06:48 by cacharle #+# #+# */ +/* Updated: 2020/12/14 15:18:09 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef ITER_HPP +# define ITER_HPP + +# include <iostream> + +template<typename T> +void iter(T* ptr, size_t len, void (*f)(T const& 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; +} + +#endif diff --git a/cpp07/ex01/iter.cpp b/cpp07/ex01/main.cpp index 831286f..6ac8e82 100644 --- a/cpp07/ex01/iter.cpp +++ b/cpp07/ex01/main.cpp @@ -1,30 +1,17 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* iter.cpp :+: :+: :+: */ +/* main.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 20:02:19 by charles #+# #+# */ -/* Updated: 2020/12/11 15:45:09 by charles ### ########.fr */ +/* Updated: 2020/12/14 15:16:32 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include <iostream> - -template<typename T> -void iter(T* ptr, size_t len, void (*f)(T const& x)) -{ - for (size_t i = 0; i < len; i++) - f(ptr[i]); -} - -/* sel-melc says const& */ -template<typename T> -void timeTwo(T const& x) -{ - x *= 2; -} +#include "iter.hpp" int main() { @@ -34,9 +21,7 @@ int main() std::cout << intArray[i] << ", "; std::cout << std::endl; iter(intArray, intArraySize, timeTwo<int>); - for (size_t i = 0; i < intArraySize; i++) - std::cout << intArray[i] << ", "; - std::cout << std::endl; + std::cout << "--------------------------------------" << std::endl; float floatArray[] = {1.1, 2.2, 3.3, 4.3, 10.001, 20.9, 30.3, -1.2, -2.4}; @@ -45,9 +30,7 @@ int main() std::cout << floatArray[i] << ", "; std::cout << std::endl; iter(floatArray, floatArraySize, timeTwo<float>); - for (size_t i = 0; i < floatArraySize; i++) - std::cout << floatArray[i] << ", "; - std::cout << std::endl; + std::cout << "--------------------------------------" << std::endl; unsigned int uintArray[] = {1, 2, 3, 4, 10, 20, 30, 100, 2000}; @@ -56,9 +39,6 @@ int main() std::cout << uintArray[i] << ", "; std::cout << std::endl; iter(uintArray, uintArraySize, timeTwo<unsigned int>); - for (size_t i = 0; i < uintArraySize; i++) - std::cout << uintArray[i] << ", "; - std::cout << std::endl; return 0; } |
