This commit is contained in:
noffie 2024-12-10 16:47:22 +01:00
parent 3afe24c9a8
commit 96e6514337
5 changed files with 23 additions and 33 deletions

View file

@ -100,7 +100,7 @@ FetchContent_Declare(
FetchContent_MakeAvailable(lua) 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 # Helper Function: Set Common Target Properties

View file

@ -5,6 +5,9 @@
#include <mutex> #include <mutex>
#include <utility> #include <utility>
#include <iostream>
#include <string>
/** /**
* @brief A thread-safe dynamic array container class * @brief A thread-safe dynamic array container class
* *
@ -160,6 +163,22 @@ public:
return size_; 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: private:
std::unique_ptr<T[]> data_; ///< Underlying array storage std::unique_ptr<T[]> data_; ///< Underlying array storage
std::size_t size_; ///< Number of elements in the array std::size_t size_; ///< Number of elements in the array

View file

@ -39,16 +39,9 @@ void SortingTester::load_internal()
void SortingTester::populate(const populate_function& f) void SortingTester::populate(const populate_function& f)
{ {
std::cout << "[List(" << list.size() << ")] [ ";
for (size_t i = 0; i < list.size(); i++) for (size_t i = 0; i < list.size(); i++)
{ {
f(i, list[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;
} }

View file

@ -126,32 +126,11 @@ public:
if (!is_sorted()) if (!is_sorted())
{ {
std::cerr << "[ERROR] The algorithm \"" << function_name << "\" did not sort the list" << std::endl; std::cerr << "[ERROR] The algorithm \"" << function_name << "\" did not sort the list" << std::endl;
std::cerr << "[List] [ "; std::cerr << list << std::endl;
for (size_t i = 0; i < list.size(); i++)
{
if(i == list.size()-1)
{
std::cerr << list[i] << " ]";
continue;
}
std::cerr << list[i] << ", ";
}
std::flush(std::cerr); std::flush(std::cerr);
std::terminate(); 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; result.count_comparisons = result.count_equal + result.count_greater + result.count_less;
active_result = nullptr; active_result = nullptr;

View file

@ -82,8 +82,7 @@ int main(int argc, char** argv)
std::cout << "\nPress any key to exit..." << std::endl; std::cout << "\nPress any key to exit..." << std::endl;
getchar(); // getchar();
return 0;
#endif #endif