Skip to content

Allow easy printing ranges of objects#4488

Merged
pwojcikdev merged 1 commit intonanocurrency:developfrom
pwojcikdev:object-streamed-range
Mar 13, 2024
Merged

Allow easy printing ranges of objects#4488
pwojcikdev merged 1 commit intonanocurrency:developfrom
pwojcikdev:object-streamed-range

Conversation

@pwojcikdev
Copy link
Copy Markdown
Contributor

This is a small addition to logging framework that allows to quickly print a range of objects as an array. From what I heard native support for printing ranges is coming with C++23, until then this should work out of the box with most types in our codebase.

Example usage:

node.logger.debug (nano::log::type::tcp_channels, "Channels: {}", nano::streamed_range (channels | std::views::transform ([] (auto const & entry) {
	return entry.channel;
})));

@pwojcikdev
Copy link
Copy Markdown
Contributor Author

Only after implementing this, I realized that it's possible to do this out of the box without having to wait for C++23, relying on built-in fmt library range printing:

node.logger.debug (nano::log::type::tcp_channels, "Channels [{}]: {}", channels.size (), channels | std::views::transform ([] (auto const & entry) {
	return nano::streamed (entry.channel);
}));

Both approaches work, up to you whether it's worth merging this one.

@pwojcikdev pwojcikdev merged commit 97cc02c into nanocurrency:develop Mar 13, 2024
@pwojcikdev pwojcikdev deleted the object-streamed-range branch March 13, 2024 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants