-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Range support #1953
Range support #1953
Conversation
404fb19
to
bffd834
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks for the PR! Just a few minor comments inline.
include/fmt/ranges.h
Outdated
|
||
# define FMT_DECLTYPE_RETURN(val) \ | ||
->decltype(val) { return val; } \ | ||
static_assert(true, "a") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this static assert for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the static assert makes it so that a semi colon is required after the macro, which mostly just helps clang-format handle the code better. the "a" is to silence a clang-tidy warning to replace the statement with a unary static assert. mostly a habit of mine but i'm not sure if it's needed here
bffd834
to
8f39926
Compare
include/fmt/core.h
Outdated
@@ -1207,6 +1211,11 @@ template <typename Context> struct arg_mapper { | |||
return 0; | |||
} | |||
|
|||
template <typename T, std::size_t N> | |||
FMT_CONSTEXPR auto map(T const (&values)[N]) -> T const (&)[N] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
T const -> const T
8f39926
to
c317045
Compare
c317045
to
17070bf
Compare
Thank you! |
I agree that my contributions are licensed under the {fmt} license, and agree to future changes to the licensing.
this PR adds support for ranges when the
begin/end
members are not const. this is done by copying the range, since in those cases the range is likely to be a view, so a copy is cheap. if we want to be more restrictive, we can instead only do so when the object isnothrow_copy_constructible
.instead of using
begin/end
member functions, i've chosen to extend support for when they're found by argument dependent lookup, with a special case for C arrays. this is to be more consistent with the rest of the language, as the same is done for c++20 ranges and range-for loops.an alternative to copying the range would be to forward the arguments, rather than capturing them as
const&
. but i'm not sure if that would be preferable.