Skip to content

Commit

Permalink
Added support for vectors in debug namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
spirosmaggioros committed Aug 12, 2024
1 parent a51b34e commit 6deea62
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/helpers/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,32 @@

#ifdef __cplusplus
#include <iostream>
#include <type_traits>
#endif

namespace DEBUG {
template <typename T>
void print_arguments(T &&t) { // single argument
void print_arguments(const T &t) { // single argument
std::cout << t << ' ';
}

template <typename T>
void print_arguments(const std::vector<T> &t){ // vectors as arguments
for(const T& x : t) {
std::cout << x << ' ';
}
}

template <class T, typename ...Args>
void print_arguments(const std::vector<T> &t, Args&& ...args) { // multiple args
for(const T& x : t) {
std::cout << x << ' ';
}
print_arguments(std::forward<Args>(args)...);
}

template <typename T, typename ...Args>
void print_arguments(T &&t, Args&& ...args) { // multiple arguments
void print_arguments(const T &t, Args&& ...args) { // single args
std::cout << t << ' ';
print_arguments(std::forward<Args>(args)...);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/helpers/debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ TEST_CASE("Testing get args for debug namespace") {

CHECK_NOTHROW(DEBUG::get_args(shortest_path, 0, 2));
}

TEST_CASE("Testing get args for debug namespace with vectors") {
auto it = [&](int a, int b) -> std::vector<int> {
return {a, b};
};
std::vector<int> passed = {2, 4};
CHECK_NOTHROW(DEBUG::get_args(it, passed));
}

0 comments on commit 6deea62

Please sign in to comment.