aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-02-01 09:48:31 +0100
committerCharles <sircharlesaze@gmail.com>2020-02-01 09:48:31 +0100
commit6e191a07bbc57d73152ba886b6f76f694a97e525 (patch)
treeb37718035e5a9b31bc3a5875b4e12a2305021a39
parent46b9e6f61275c4ed4cd2e8f319cad4f6bc73100f (diff)
downloadft_containers-6e191a07bbc57d73152ba886b6f76f694a97e525.tar.gz
ft_containers-6e191a07bbc57d73152ba886b6f76f694a97e525.tar.bz2
ft_containers-6e191a07bbc57d73152ba886b6f76f694a97e525.zip
src test dir, makefile, Added subject
-rw-r--r--.gitignore1
-rw-r--r--List.cpp89
-rw-r--r--List.hpp95
-rw-r--r--Makefile33
-rw-r--r--src/List.hpp184
-rw-r--r--src/Stack.hpp (renamed from Stack.htpp)0
-rw-r--r--src/Vector.hpp (renamed from Vector.hpp)0
-rw-r--r--subject.pdfbin0 -> 1269450 bytes
-rw-r--r--test/main.cpp7
9 files changed, 225 insertions, 184 deletions
diff --git a/.gitignore b/.gitignore
index fd1c1ec..a39e06b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
*.o
*.ghc
a.out
+ft_containers_test
diff --git a/List.cpp b/List.cpp
deleted file mode 100644
index f88ca36..0000000
--- a/List.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-#include "List.hpp"
-
-ft::List::List(const allocator_type& alloc = allocator_type())
-{
- front = nullptr;
- back = nullptr;
- size = 0;
-
-}
-
-ft::List::~List()
-{
- while (size > 0)
- pop_front();
-}
-
-ft::List::bool empty() const
-{
- return front == nullptr;
-}
-ft::List::size_type size() const
-{
- return size;
-}
-
-ft::List::reference front()
-{
- return *front;
-}
-
-ft::List::reference back()
-{
- return *back;
-}
-
-ft::List::void push_front (const value_type& val)
-{
- PrivateList *nfront = new PrivateList(val);
- nfront->next = front;
- front = nfront;
- if (back == nullptr)
- back = front;
- size++;
-}
-
-ft::List::void pop_front()
-{
- t_llist *nfront = front->next;
- if (size == 1)
- back = nullptr;
- delete front;
- front = nfront;
- size--;
-}
-
-ft::List::void push_back (const value_type& val)
-{
- PrivateList *nback = new PrivateList(val);
- if (empty())
- {
- back = nback;
- front = back;
- return;
- }
- back->next = nback;
- back = nback;
- size++;
-}
-
-ft::List::void pop_back()
-{
- t_llist *tmp = front;
-
- while (tmp->next != back)
- tmp = tmp->next;
- delete back;
- back = tmp;
-}
-
-ft::List::PrivateList::PrivateList(const value_type& val);
-{
- next = nullptr;
- val = val;
-}
-
-ft::List::PrivateList::~PrivateList()
-{
- delete val;
-}
diff --git a/List.hpp b/List.hpp
deleted file mode 100644
index 57a9a8f..0000000
--- a/List.hpp
+++ /dev/null
@@ -1,95 +0,0 @@
-#ifndef LIST_HPP
-# define LIST_HPP
-
-namespace ft
-{
- template < class T, class Alloc = allocator<T> >
- class List
- {
- public:
- List(const allocator_type& alloc = allocator_type());
- // List(size_type n, const value_type& val = value_type(), const allocator_type& alloc = allocator_type());
- // template <class InputIterator>
- // List(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type());
- // List(const list& x);
- ~List();
- // List& operator = (const List& x);
-
- // iterators
- // iterator begin();
- // const_iterator begin() const;
- // iterator end();
- // const_iterator end() const;
- // reverse_iterator rbegin();
- // const_reverse_iterator rbegin() const;
- // reverse_iterator rend();
- // const_reverse_iterator rend() const;
-
- // capacity
- bool empty() const;
- size_type size() const;
- size_type max_size() const;
-
- // element access
- reference front();
- const_reference front() const;
- reference back();
- const_reference back();
-
- // modifiers
- // template <class InputIterator>
- // void assign (InputIterator first, InputIterator last);
- // void assign (size_type n, const value_type& val);
- void push_front (const value_type& val);
- void pop_front();
- void push_back (const value_type& val);
- void pop_back();
- // iterator insert (iterator position, const value_type& val);
- // void insert (iterator position, size_type n, const value_type& val);
- // template <class InputIterator>
- // void insert (iterator position, InputIterator first, InputIterator last);
- // iterator erase (iterator position);
- // iterator erase (iterator first, iterator last);
- // void swap (list& x);
- // void resize (size_type n, value_type val = value_type());
- // void clear();
-
- // operations
- // void splice (iterator position, list& x);
- // void splice (iterator position, list& x, iterator i);
- // void splice (iterator position, list& x, iterator first, iterator last);
- // void remove (const value_type& val);
- // template <class Predicate>
- // void remove_if (Predicate pred);
- // void unique();
- // template <class BinaryPredicate>
- // void unique (BinaryPredicate binary_pred);
- //
- // void merge (list& x);
- // template <class Compare>
- // void merge (list& x, Compare comp);
- // void sort();
- // template <class Compare>
- // void sort (Compare comp);
- // void reverse();
-
- // observers
- // allocator_type get_allocator() const;
-
- private:
- class PrivateList
- {
- public:
- PrivateList(const value_type& val);
- ~PrivateList();
-
- PrivateList *next;
- T val;
- }
- PrivateList *front;
- PrivateList *back;
- size_type size;
- };
-}
-
-#endif
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..4837cab
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,33 @@
+RM = rm -f
+
+CC = clang++
+CCFLAGS = -Wall -Wextra #-Werror
+
+SRC_DIR = src
+TEST_DIR = test
+OBJ_DIR = obj
+
+TEST_SRC = $(shell find $(TEST_DIR) -type f -name "*.cpp")
+OBJ = $(TEST_SRC:$(TEST_DIR)/%.cpp=$(OBJ_DIR)/%.o)
+$(info $(OBJ))
+
+NAME = ft_containers_test
+
+all: prebuild $(NAME)
+
+prebuild:
+ if [ ! -d $(OBJ_DIR) ]; then mkdir $(OBJ_DIR); fi
+
+$(NAME): $(OBJ)
+ $(CC) -o $@ $^
+
+$(OBJ_DIR)/%.o: $(TEST_DIR)/%.cpp
+ $(CC) $(CCFLAGS) -c -o $@ $<
+
+clean:
+ $(RM) $(OBJ)
+
+fclean: clean
+ $(RM) $(NAME)
+
+re: fclean all
diff --git a/src/List.hpp b/src/List.hpp
new file mode 100644
index 0000000..aca8f06
--- /dev/null
+++ b/src/List.hpp
@@ -0,0 +1,184 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* List.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/01 09:31:07 by cacharle #+# #+# */
+/* Updated: 2020/02/01 09:38:20 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef LIST_HPP
+# define LIST_HPP
+
+namespace ft
+{
+ template < typename T, typename Alloc = allocator<T> >
+ class List
+ {
+
+ typedef T value_type;
+ typedef Alloc allocator_type;
+ typedef allocator_type::reference reference;
+ typedef allocator_type::const_reference const_reference;
+ typedef allocator_type::pointer pointer;
+ typedef allocator_type::const_pointer const_pointer;
+
+
+
+ public:
+ List(const allocator_type& alloc = allocator_type());
+ {
+ front = nullptr;
+ back = nullptr;
+ size = 0;
+ }
+ // List(size_type n, const value_type& val = value_type(), const allocator_type& alloc = allocator_type());
+ // template <class InputIterator>
+ // List(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type());
+ // List(const list& x);
+ ~List()
+ {
+ while (size > 0)
+ pop_front();
+ }
+ // List& operator = (const List& x);
+
+ // iterators
+ // iterator begin();
+ // const_iterator begin() const;
+ // iterator end();
+ // const_iterator end() const;
+ // reverse_iterator rbegin();
+ // const_reverse_iterator rbegin() const;
+ // reverse_iterator rend();
+ // const_reverse_iterator rend() const;
+
+ // capacity
+ bool empty() const
+ {
+ return front == nullptr;
+ }
+ size_type size() const
+ {
+ return size;
+ }
+
+ size_type max_size() const;
+
+ // element access
+ reference front()
+ {
+ return *front;
+ }
+
+ reference back()
+ {
+ return *back;
+ }
+ const_reference front() const;
+ const_reference back();
+
+ // modifiers
+ // template <class InputIterator>
+ // void assign (InputIterator first, InputIterator last);
+ // void assign (size_type n, const value_type& val);
+ void push_front (const value_type& val)
+ {
+ PrivateList *nfront = new PrivateList(val);
+ nfront->next = front;
+ front = nfront;
+ if (back == nullptr)
+ back = front;
+ size++;
+ }
+ void pop_front()
+ {
+ t_llist *nfront = front->next;
+ if (size == 1)
+ back = nullptr;
+ delete front;
+ front = nfront;
+ size--;
+ }
+ void push_back (const value_type& val)
+ {
+ PrivateList *nback = new PrivateList(val);
+ if (empty())
+ {
+ back = nback;
+ front = back;
+ return;
+ }
+ back->next = nback;
+ back = nback;
+ size++;
+ }
+ void pop_back()
+ {
+ t_llist *tmp = front;
+
+ while (tmp->next != back)
+ tmp = tmp->next;
+ delete back;
+ back = tmp;
+ }
+ // iterator insert (iterator position, const value_type& val);
+ // void insert (iterator position, size_type n, const value_type& val);
+ // template <class InputIterator>
+ // void insert (iterator position, InputIterator first, InputIterator last);
+ // iterator erase (iterator position);
+ // iterator erase (iterator first, iterator last);
+ // void swap (list& x);
+ // void resize (size_type n, value_type val = value_type());
+ // void clear();
+
+ // operations
+ // void splice (iterator position, list& x);
+ // void splice (iterator position, list& x, iterator i);
+ // void splice (iterator position, list& x, iterator first, iterator last);
+ // void remove (const value_type& val);
+ // template <class Predicate>
+ // void remove_if (Predicate pred);
+ // void unique();
+ // template <class BinaryPredicate>
+ // void unique (BinaryPredicate binary_pred);
+ //
+ // void merge (list& x);
+ // template <class Compare>
+ // void merge (list& x, Compare comp);
+ // void sort();
+ // template <class Compare>
+ // void sort (Compare comp);
+ // void reverse();
+
+ // observers
+ // allocator_type get_allocator() const;
+
+ private:
+ class PrivateList
+ {
+ public:
+ PrivateList(const value_type& val)
+ {
+ next = nullptr;
+ val = val;
+ }
+
+ ~PrivateList()
+ {
+ delete val;
+ }
+
+ PrivateList *next;
+ T val;
+ }
+ PrivateList *front;
+ PrivateList *back;
+ size_type size;
+ };
+}
+
+#endif
diff --git a/Stack.htpp b/src/Stack.hpp
index 64bfc66..64bfc66 100644
--- a/Stack.htpp
+++ b/src/Stack.hpp
diff --git a/Vector.hpp b/src/Vector.hpp
index 0f21995..0f21995 100644
--- a/Vector.hpp
+++ b/src/Vector.hpp
diff --git a/subject.pdf b/subject.pdf
new file mode 100644
index 0000000..c814d3e
--- /dev/null
+++ b/subject.pdf
Binary files differ
diff --git a/test/main.cpp b/test/main.cpp
new file mode 100644
index 0000000..156eae7
--- /dev/null
+++ b/test/main.cpp
@@ -0,0 +1,7 @@
+#include <iostream>
+
+int main()
+{
+ std::cout << "bonjour" << std::endl;
+ return 0;
+}