Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow easy printing ranges of objects #4488

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

pwojcikdev
Copy link
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
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
24 of 27 checks passed
@pwojcikdev pwojcikdev deleted the object-streamed-range branch March 13, 2024 08:56
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants