commit 35fc155f65ad515df887c2911679601ae31b4eb5 Author: adjoly Date: Mon Apr 14 19:39:20 2025 +0200 「✨」 feat: finished ex00 diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96e6889 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.direnv +*.o +obj/ +compile_commands.json +.cache +*.d diff --git a/ex00/Makefile b/ex00/Makefile new file mode 100644 index 0000000..7225175 --- /dev/null +++ b/ex00/Makefile @@ -0,0 +1,60 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: adjoly +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/10/25 16:09:27 by adjoly #+# #+# # +# Updated: 2025/04/14 19:06:23 by adjoly ### ########.fr # +# # +# **************************************************************************** # + +SHELL = bash + +NAME = easyfind + +CC = c++ + +OBJSDIR = obj/ + +SRCS = $(shell find . -name '*.cpp') + +OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o)) + +FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP + +RED = \033[0;31m +GREEN = \033[0;32m +YELLOW = \033[1;33m +PURPLE = \e[0;35m +NC = \033[0m +DELETE = \x1B[2K\r + +ifeq ($(VERBOSE),true) + FLAGS += -D VERBOSE +endif + +all: $(NAME) + +$(NAME): $(OBJS) + @$(CC) $(FLAGS) -I . $(OBJS) -o $(NAME) + @printf "$(YELLOW)「✨」($(NAME)) Program compiled\n" + +$(OBJSDIR)%.o: %.cpp + @mkdir -p $(@D) + @$(CC) $(FLAGS) -I . -c $< -o $@ + @printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n" + +clean: + @rm -f $(OBJS) + @printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n" + +fclean: clean + @rm -f $(NAME) + @rm -Rf $(OBJSDIR) + @printf "$(RED)「🗑️」($(NAME)) Program deleted\n" + +re: fclean all + +.PHONY: clean fclean all re diff --git a/ex00/easyfind b/ex00/easyfind new file mode 100755 index 0000000..bea68be Binary files /dev/null and b/ex00/easyfind differ diff --git a/ex00/easyfind.hpp b/ex00/easyfind.hpp new file mode 100644 index 0000000..92fbc3f --- /dev/null +++ b/ex00/easyfind.hpp @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* easyfind.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/14 19:07:43 by adjoly #+# #+# */ +/* Updated: 2025/04/14 19:33:52 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include +#include +#include + +template typename T::iterator easyfind(T val, int what) { + typename T::iterator it = std::find(val.begin(), val.end(), what); + if (it == val.end()) + throw std::runtime_error("value not found"); + return it; +} diff --git a/ex00/main.cpp b/ex00/main.cpp new file mode 100644 index 0000000..dfbbc04 --- /dev/null +++ b/ex00/main.cpp @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/14 19:33:56 by adjoly #+# #+# */ +/* Updated: 2025/04/14 19:39:02 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "easyfind.hpp" +#include +#include +#include + +std::vector *newVec() { + std::vector *vec = new std::vector; + for (size_t i = 0; i < 10; i++) { + vec->push_back(i); + } + return vec; +} + +int main(void) { + std::vector *vec = newVec(); + try { + std::vector::iterator it = easyfind >(*vec, 8); + std::cout << "found value : " << *it << std::endl; + } catch (std::runtime_error &e) { + std::cerr << e.what() << std::endl; + } + try { + std::vector::iterator it = easyfind >(*vec, 13); + std::cout << "found value : " << *it << std::endl; + } catch (std::runtime_error &e) { + std::cerr << e.what() << std::endl; + } +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c206742 --- /dev/null +++ b/flake.lock @@ -0,0 +1,79 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1733312601, + "narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1734649271, + "narHash": "sha256-4EVBRhOjMDuGtMaofAIqzJbg4Ql7Ai0PSeuVZTHjyKQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d70bd19e0a38ad4790d3913bf08fcbfc9eeca507", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1733096140, + "narHash": "sha256-1qRH7uAUsyQI7R1Uwl4T+XvdNv778H0Nb5njNrqvylY=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" + } + }, + "pogit": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1733518808, + "narHash": "sha256-tKqXoNTG1PGOnHjb6UvkSpKOZFDXDmZt1p0mw5Cic58=", + "owner": "y-syo", + "repo": "pogit", + "rev": "c3cb3fa9aefcf9e065ee27f2daa62a3826d48169", + "type": "github" + }, + "original": { + "owner": "y-syo", + "repo": "pogit", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "pogit": "pogit" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..68e9f43 --- /dev/null +++ b/flake.nix @@ -0,0 +1,36 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + pogit = { + url = "github:y-syo/pogit"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = inputs@{ nixpkgs, ... }: + let + supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f { + pkgs = import nixpkgs { inherit system; }; + }); + in { + devShells = forEachSupportedSystem ({ pkgs }: { + default = pkgs.mkShell.override + {} + { + hardeningDisable = [ "all" ]; + packages = with pkgs; [ + git + gdb + gcc11 + clang_12 + valgrind + compiledb + norminette + inputs.pogit.packages.${pkgs.system}.default + ]; + }; + }); + }; +} +