Skip to content

Added formatter for bit_reference-like types - #3570

Merged
vitaut merged 5 commits into
fmtlib:masterfrom
phprus:vector-bool
Aug 6, 2023
Merged

vitaut merged 5 commits into
fmtlib:masterfrom
phprus:vector-bool

Conversation

@phprus

@phprus phprus commented Aug 4, 2023

Copy link
Copy Markdown
Contributor

Fix for issue #3567

Test is based on #3569

@phprus
phprus marked this pull request as draft August 4, 2023 19:44
@phprus
phprus marked this pull request as ready for review August 4, 2023 20:18
@phprus
phprus marked this pull request as draft August 4, 2023 20:21
@phprus
phprus marked this pull request as ready for review August 4, 2023 21:02
@phprus

phprus commented Aug 4, 2023

Copy link
Copy Markdown
Contributor Author

Final version.
Ready for review.

Comment thread include/fmt/std.h Outdated
@phprus
phprus marked this pull request as draft August 5, 2023 08:29
@phprus phprus changed the title Added formatter for std::vector<bool>::reference Added formatter for bit_reference-like types Aug 5, 2023
@phprus

phprus commented Aug 5, 2023

Copy link
Copy Markdown
Contributor Author

@vitaut

Final-2 version :)
Ready for review.

@phprus
phprus marked this pull request as ready for review August 5, 2023 09:46
Comment thread include/fmt/std.h Outdated
Comment thread test/std-test.cc

@vitaut vitaut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

This looks like a lot of effort and implementation-specific code for such a corner case. I suggest just using std::addressoff and replacing FMT_CONSTEXPR with FMT_COSTEXPR20 in the value ctor overload that uses it. It only affects compile-time formatting anyway that requires a recent standard.

phprus and others added 2 commits August 5, 2023 22:13
Co-authored-by: Felix <felix-antoine.constantin@polymtl.ca>
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
@phprus

phprus commented Aug 5, 2023

Copy link
Copy Markdown
Contributor Author

@vitaut
Done.

@wangzw

wangzw commented Aug 6, 2023

Copy link
Copy Markdown
Contributor

Works well for me. Thanks

Comment thread include/fmt/std.h
Comment thread include/fmt/std.h Outdated
Comment thread include/fmt/std.h Outdated
Comment thread include/fmt/std.h
Comment thread include/fmt/std.h Outdated
Comment on lines +424 to +438
#ifdef _LIBCPP_VERSION

// Workaround for libc++ incompatibility with C++ standard.
// According to the Standard, `bitset::operator[] const` returns bool.
FMT_EXPORT
template <typename C, typename Char>
struct formatter<std::__bit_const_reference<C>, Char> : formatter<bool, Char> {
template <typename FormatContext>
FMT_CONSTEXPR20 auto format(const std::__bit_const_reference<C>& v,
FormatContext& ctx) const -> decltype(ctx.out()) {
return formatter<bool, Char>::format(v, ctx);
}
};

#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be replaced by a specialization of is_bit_reference_like for __bit_const_reference which seems a bit cleaner (no duplicate formatter).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

…ol>::reference

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
phprus added 2 commits August 6, 2023 22:23
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
@phprus
phprus requested a review from vitaut August 6, 2023 17:45
@vitaut
vitaut merged commit aeb6ad4 into fmtlib:master Aug 6, 2023
@vitaut

vitaut commented Aug 6, 2023

Copy link
Copy Markdown
Contributor

Thank you!

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.

3 participants