Skip to content

Commit

Permalink
Change printing of vectors from [] to {}
Browse files Browse the repository at this point in the history
  • Loading branch information
hivert committed Oct 27, 2023
1 parent b4f1dda commit a9151f3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions include/epu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define HPCOMBI_EPU_HPP_INCLUDED

#include <array>
#include <string>
#include <cassert>
#include <cstdint>
#include <functional> // less<>, equal_to<>
Expand Down Expand Up @@ -727,6 +728,8 @@ namespace std {

inline std::ostream &operator<<(std::ostream &stream, HPCombi::epu8 const &a);

inline std::string to_string(HPCombi::epu8 const &a);

/** We also specialize the struct
* - std::equal_to<epu8>
* - std::not_equal_to<epu8>
Expand Down
10 changes: 8 additions & 2 deletions include/epu_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,19 @@ inline bool is_permutation(epu8 v, const size_t k) {
namespace std {

inline std::ostream &operator<<(std::ostream &stream, HPCombi::epu8 const &a) {
stream << "[" << std::setw(2) << unsigned(a[0]);
stream << "{" << std::setw(2) << unsigned(a[0]);
for (unsigned i = 1; i < 16; ++i)
stream << "," << std::setw(2) << unsigned(a[i]);
stream << "]";
stream << "}";
return stream;
}

inline std::string to_string(HPCombi::epu8 const &a) {
std::ostringstream ss;
ss << a;
return ss.str();
}

template <> struct equal_to<HPCombi::epu8> {
bool operator()(const HPCombi::epu8 &lhs, const HPCombi::epu8 &rhs) const {
return HPCombi::equal(lhs, rhs);
Expand Down
12 changes: 6 additions & 6 deletions tests/test_perm_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,28 +260,28 @@ TEMPLATE_TEST_CASE_METHOD(Fixture1, "operator_insert", "[AllPerm][011]",
PermTypes) {
std::ostringstream out, out2;
out << Fixture1<TestType>::zero;
out2 << "[ 0";
out2 << "{ 0";
for (size_t i = 1; i < Fixture1<TestType>::VectType::Size(); i++)
out2 << ", 0";
out2 << "]";
out2 << "}";
REQUIRE(out.str() == out2.str());

out.str("");
out2.str("");
out << Fixture1<TestType>::V01;
out2 << "[ 0, 1";
out2 << "{ 0, 1";
for (size_t i = 2; i < Fixture1<TestType>::VectType::Size(); i++)
out2 << ", 0";
out2 << "]";
out2 << "}";
REQUIRE(out.str() == out2.str());

out.str("");
out2.str("");
out << Fixture1<TestType>::PPa;
out2 << "[ 1, 2, 3, 4, 0";
out2 << "{ 1, 2, 3, 4, 0";
for (size_t i = 5; i < Fixture1<TestType>::VectType::Size(); i++)
out2 << "," << std::setw(2) << i;
out2 << "]";
out2 << "}";
REQUIRE(out.str() == out2.str());
}

Expand Down

0 comments on commit a9151f3

Please sign in to comment.