From 96e65143379442ac241c726d26ca0e9a61bed0a6 Mon Sep 17 00:00:00 2001 From: noffie Date: Tue, 10 Dec 2024 16:47:22 +0100 Subject: [PATCH] save --- CMakeLists.txt | 2 +- include/list.hpp | 19 +++++++++++++++++++ src/SortingTester.cpp | 9 +-------- src/SortingTester.h | 23 +---------------------- src/main.cpp | 3 +-- 5 files changed, 23 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a017a9..6b32652 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,7 +100,7 @@ FetchContent_Declare( FetchContent_MakeAvailable(lua) -set(LUA_BUILD_INTERPRETER ON) +set(LUA_BUILD_INTERPRETER ON CACHE BOOL "Build the Lua interpreter" FORCE) # ======================================================== # Helper Function: Set Common Target Properties diff --git a/include/list.hpp b/include/list.hpp index a580939..371007f 100644 --- a/include/list.hpp +++ b/include/list.hpp @@ -5,6 +5,9 @@ #include #include +#include +#include + /** * @brief A thread-safe dynamic array container class * @@ -160,6 +163,22 @@ public: return size_; } + friend std::ostream& operator<<(std::ostream& os, const List& list) + { + os << "[List] List( type: {" << typeid(T).name() << "}, size: " << list.size_ << ") [ "; + for (size_t i = 0; i < list.size_ - 1; i++) + { + os << list[i] << ", "; + } + os << list[list.size_ - 1] << " ]"; + return os; + } + + static std::string type_name() + { + return "List<" + std::string(typeid(T).name()) + ">"; + } + private: std::unique_ptr data_; ///< Underlying array storage std::size_t size_; ///< Number of elements in the array diff --git a/src/SortingTester.cpp b/src/SortingTester.cpp index 34edabf..aec1fec 100644 --- a/src/SortingTester.cpp +++ b/src/SortingTester.cpp @@ -39,16 +39,9 @@ void SortingTester::load_internal() void SortingTester::populate(const populate_function& f) { - std::cout << "[List(" << list.size() << ")] [ "; for (size_t i = 0; i < list.size(); i++) { f(i, list[i]); - if(i == list.size()-1) - { - std::cout << list[i] << " ]\n"; - break; - } - std::cout << list[i] << ", "; } - std::flush(std::cout); + std::cout << list << std::endl; } diff --git a/src/SortingTester.h b/src/SortingTester.h index 6b4a665..b823a8c 100644 --- a/src/SortingTester.h +++ b/src/SortingTester.h @@ -126,32 +126,11 @@ public: if (!is_sorted()) { std::cerr << "[ERROR] The algorithm \"" << function_name << "\" did not sort the list" << std::endl; - std::cerr << "[List] [ "; - for (size_t i = 0; i < list.size(); i++) - { - if(i == list.size()-1) - { - std::cerr << list[i] << " ]"; - continue; - } - std::cerr << list[i] << ", "; - } + std::cerr << list << std::endl; std::flush(std::cerr); std::terminate(); } - std::cout << "[sorted: List(" << list.size() << ")] [ "; - for (size_t i = 0; i < list.size(); i++) - { - if(i == list.size()-1) - { - std::cout << list[i] << " ]\n"; - break; - } - std::cout << list[i] << ", "; - } - std::flush(std::cout); - result.count_comparisons = result.count_equal + result.count_greater + result.count_less; active_result = nullptr; diff --git a/src/main.cpp b/src/main.cpp index dd033f4..d5108ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,8 +82,7 @@ int main(int argc, char** argv) std::cout << "\nPress any key to exit..." << std::endl; - getchar(); - return 0; + // getchar(); #endif