diff --git a/librerie/exercise1/list/list.cpp b/librerie/exercise1/list/list.cpp index ac28408..371af2d 100644 --- a/librerie/exercise1/list/list.cpp +++ b/librerie/exercise1/list/list.cpp @@ -148,6 +148,10 @@ bool List::operator!=(const List& list) const noexcept{ tmp->next = nullptr; delete tmp; size--; + + if(head==nullptr){ + tail=nullptr; + } } } diff --git a/librerie/exercise2/container/container.cpp b/librerie/exercise2/container/container.cpp old mode 100755 new mode 100644 index d374ceb..6bbe4bf --- a/librerie/exercise2/container/container.cpp +++ b/librerie/exercise2/container/container.cpp @@ -1,10 +1,18 @@ namespace lasd { -/* ************************************************************************** */ +template +void AuxFoldExists(const Data& dat, const void* val, void* exists){ + if(dat == *((Data*)val)){ + *((bool*)exists) = true; + } +} -// ... - -/* ************************************************************************** */ +template +bool FoldableContainer::Exists(const Data& dat) const noexcept{ + bool exists = false; + FoldPreOrder(&AuxFoldExists, &dat, &exists); + return exists; +} } diff --git a/librerie/exercise2/container/container.hpp b/librerie/exercise2/container/container.hpp old mode 100755 new mode 100644 index c7c268a..c28cc43 --- a/librerie/exercise2/container/container.hpp +++ b/librerie/exercise2/container/container.hpp @@ -2,226 +2,175 @@ #ifndef CONTAINER_HPP #define CONTAINER_HPP -/* ************************************************************************** */ - #include #include -/* ************************************************************************** */ - namespace lasd { -/* ************************************************************************** */ - class Container { private: - // ... - protected: - // ... + ulong size = 0; public: // Destructor - // ~Container() specifiers - - /* ************************************************************************ */ + virtual ~Container() = default; // Copy assignment - // type operator=(argument); // Copy assignment of abstract types should not be possible. + Container& operator=(const Container&) = delete; // Copy assignment of abstract types should not be possible. // Move assignment - // type operator=(argument); // Move assignment of abstract types should not be possible. - - /* ************************************************************************ */ + Container& operator=(Container&&) noexcept = delete;; // Move assignment of abstract types should not be possible. // Comparison operators - // type operator==(argument) specifiers; // Comparison of abstract types might not be possible. - // type operator!=(argument) specifiers; // Comparison of abstract types might not be possible. - - /* ************************************************************************ */ + bool operator==(const Container&) const noexcept = delete; // Comparison of abstract types might not be possible. + bool operator!=(const Container&&) const noexcept = delete; // Comparison of abstract types might not be possible. // Specific member functions - // type Empty() specifiers; // (concrete function should not throw exceptions) + virtual bool Empty() const noexcept { + return (size == 0); + } // (concrete function should not throw exceptions) - // type Size() specifiers; // (concrete function should not throw exceptions) - - // type Clear() specifiers; + virtual ulong Size() const noexcept { + return size; + } // (concrete function should not throw exceptions) + virtual void Clear() = 0; }; /* ************************************************************************** */ + + template -class LinearContainer { // Must extend Container +class LinearContainer : virtual public Container{ // Must extend Container private: - // ... - protected: - // ... - public: // Destructor - // ~LinearContainer() specifiers - - /* ************************************************************************ */ + virtual ~LinearContainer() = default; // Copy assignment - // type operator=(argument); // Copy assignment of abstract types should not be possible. + LinearContainer& operator=(const LinearContainer&) = delete; // Copy assignment of abstract types should not be possible. // Move assignment - // type operator=(argument); // Move assignment of abstract types should not be possible. - - /* ************************************************************************ */ + LinearContainer& operator=(LinearContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible. // Comparison operators - // type operator==(argument) specifiers; // Comparison of abstract types might not be possible. - // type operator!=(argument) specifiers; // Comparison of abstract types might not be possible. + bool operator==(const LinearContainer&) const noexcept = delete; // Comparison of abstract types might not be possible. + bool operator!=(const LinearContainer&) const noexcept = delete; // Comparison of abstract types might not be possible. /* ************************************************************************ */ // Specific member functions - // type Front() specifiers; // (concrete function must throw std::length_error when empty) - // type Back() specifiers; // (concrete function must throw std::length_error when empty) + virtual Data& Front() const = 0; // (concrete function must throw std::length_error when empty) + virtual Data& Back() const = 0; // (concrete function must throw std::length_error when empty) - // type operator[](argument) specifiers; // (concrete function must throw std::out_of_range when out of range) + virtual Data& operator[](const ulong) const = 0; // (concrete function must throw std::out_of_range when out of range) }; -/* ************************************************************************** */ - template -class TestableContainer { // Must extend Container +class TestableContainer : virtual public Container{ // Must extend Container private: - // ... - protected: - // ... - public: // Destructor - // ~TestableContainer() specifiers - - /* ************************************************************************ */ + virtual ~TestableContainer() = default; // Copy assignment - // type operator=(argument); // Copy assignment of abstract types should not be possible. + TestableContainer& operator=(const TestableContainer&) = delete; // Copy assignment of abstract types should not be possible. // Move assignment - // type operator=(argument); // Move assignment of abstract types should not be possible. - - /* ************************************************************************ */ + TestableContainer& operator=(TestableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible. // Comparison operators - // type operator==(argument) specifiers; // Comparison of abstract types might not be possible. - // type operator!=(argument) specifiers; // Comparison of abstract types might not be possible. + bool operator==(const TestableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible. + bool operator!=(const TestableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible. /* ************************************************************************ */ // Specific member functions - // type Exists(argument) specifiers; // (concrete function should not throw exceptions) + virtual bool Exists(const Data&) const noexcept = 0; // (concrete function should not throw exceptions) }; -/* ************************************************************************** */ - template -class MappableContainer { // Must extend Container +class MappableContainer : virtual public Container { // Must extend Container private: - // ... - protected: - // ... - public: // Destructor - // ~MappableContainer() specifiers - - /* ************************************************************************ */ + virtual ~MappableContainer() = default; // Copy assignment - // type operator=(argument); // Copy assignment of abstract types should not be possible. + MappableContainer& operator=(const MappableContainer&) = delete; // Copy assignment of abstract types should not be possible. // Move assignment - // type operator=(argument); // Move assignment of abstract types should not be possible. - - /* ************************************************************************ */ + MappableContainer& operator=(MappableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible. // Comparison operators - // type operator==(argument) specifiers; // Comparison of abstract types might not be possible. - // type operator!=(argument) specifiers; // Comparison of abstract types might not be possible. - - /* ************************************************************************ */ + bool operator==(const MappableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible. + bool operator!=(const MappableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible. // Specific member functions - // typedef std::function MapFunctor; + typedef std::function MapFunctor; - // type MapPreOrder(arguments) specifiers; - // type MapPostOrder(arguments) specifiers; + virtual void MapPreOrder(const MapFunctor, void*) = 0; + virtual void MapPostOrder(const MapFunctor, void*) = 0; }; -/* ************************************************************************** */ - template -class FoldableContainer { // Must extend TestableContainer +class FoldableContainer : virtual public TestableContainer{ // Must extend TestableContainer private: - // ... - protected: - // ... - public: // Destructor - // ~FoldableContainer() specifiers - - /* ************************************************************************ */ + virtual ~FoldableContainer() = default; // Copy assignment - // type operator=(argument); // Copy assignment of abstract types should not be possible. + FoldableContainer& operator=(const FoldableContainer&) = delete; // Copy assignment of abstract types should not be possible. // Move assignment - // type operator=(argument); // Move assignment of abstract types should not be possible. - - /* ************************************************************************ */ + FoldableContainer& operator=(FoldableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible. // Comparison operators - // type operator==(argument) specifiers; // Comparison of abstract types might not be possible. - // type operator!=(argument) specifiers; // Comparison of abstract types might not be possible. - - /* ************************************************************************ */ + bool operator==(FoldableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible. + bool operator!=(FoldableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible. // Specific member functions - // typedef std::function FoldFunctor; + typedef std::function FoldFunctor; - // type FoldPreOrder(arguments) specifiers; - // type FoldPostOrder(arguments) specifiers; + virtual void FoldPreOrder(const FoldFunctor, const void*, void*) const = 0; + virtual void FoldPostOrder(const FoldFunctor, const void*, void*) const = 0; - // type Exists(argument) specifiers; // Override TestableContainer member + virtual bool Exists(const Data&) const noexcept override; // Override TestableContainer member };