ex01: init
This commit is contained in:
parent
d65e637f00
commit
23311296d0
26
ex01/Makefile
Normal file
26
ex01/Makefile
Normal file
@ -0,0 +1,26 @@
|
||||
CXX := c++
|
||||
CXXFLAGS := -std=c++98 -Wall -Wextra -Werror -g
|
||||
SRCDIR := src
|
||||
OBJDIR := obj
|
||||
NAME := ex01
|
||||
|
||||
SRCS := $(wildcard $(SRCDIR)/*.cpp)
|
||||
OBJS := $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
mkdir -p $(OBJDIR)
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR)
|
||||
|
||||
fclean: clean
|
||||
rm -fr $(NAME)
|
||||
|
||||
re: fclean
|
||||
@make --no-print-directory all
|
10
ex01/src/iter.hpp
Normal file
10
ex01/src/iter.hpp
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
template<typename T, typename U>
|
||||
void iter(T* arr, size_t len, void(*f)(U))
|
||||
{
|
||||
for (size_t i = 0; i < len; i++)
|
||||
f(arr[i]);
|
||||
}
|
25
ex01/src/main.cpp
Normal file
25
ex01/src/main.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "iter.hpp"
|
||||
#include <iostream>
|
||||
|
||||
template<typename T>
|
||||
void print(T& t)
|
||||
{
|
||||
std::cout << t << std::endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int array[] = {0, 1, 2, 3, 4, 5, 6};
|
||||
|
||||
iter(array, 7, print<int>);
|
||||
|
||||
std::string strs[] = {
|
||||
"Hello World",
|
||||
"Bonjour Monde",
|
||||
"Hallo Welt",
|
||||
"Hola Mundo"
|
||||
};
|
||||
|
||||
iter(strs, 4, print<std::string>);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user