Skip to content

Commit

Permalink
Merge pull request #317 from DNKpp/main
Browse files Browse the repository at this point in the history
Fix streamer for input-range like types
  • Loading branch information
rollbear authored Oct 7, 2023
2 parents 5458e85 + ad428fa commit 13b6433
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/trompeloeil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1381,8 +1381,8 @@ template <typename T>
using is_collection = is_detected<iterable, T>;

template <typename T,
bool = is_output_streamable<T>::value,
bool = is_collection<detail::remove_reference_t<T>>::value>
bool = is_output_streamable<const T>::value,
bool = is_collection<const detail::remove_reference_t<T>>::value>
struct streamer
{
static
Expand Down
17 changes: 17 additions & 0 deletions test/compiling_tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,23 @@ struct my_printable
int x;
};

struct my_input_range
{
using iterator = std::vector<int>::iterator;

std::vector<int> data{};

iterator begin()
{
return data.begin();
}

iterator end()
{
return data.end();
}
};

class TestOutputMock
{
public:
Expand Down
22 changes: 22 additions & 0 deletions test/compiling_tests_11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4523,6 +4523,28 @@ TEST_CASE_METHOD(
REQUIRE(os.str() == "pseudo_null_comparable");
}

TEST_CASE_METHOD(
Fixture,
"C++11: An object with non-const begin/end members, is printed using its memory representation.",
"[C++11][C++14][streaming]")
{
std::ostringstream os;
trompeloeil::print(
os,
[]
{
my_input_range range{};
range.data.emplace_back(42);
range.data.emplace_back(44);
range.data.emplace_back(44);
return range;
}());

const std::string printResult{os.str()};
const std::string expectedPrefix{std::to_string(sizeof(my_input_range)) + "-byte object={"};
REQUIRE(expectedPrefix == printResult.substr(0, expectedPrefix.size()));
}

#if !(defined(_MSC_VER) && _MSC_VER < 1910)
// Disable this test case for Microsoft Visual Studio 2015
// until a working implementation of is_null_comparable is found
Expand Down

0 comments on commit 13b6433

Please sign in to comment.