Skip to content
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

Merged
merged 1 commit into from
Oct 28, 2020
Merged

Range support #1953

merged 1 commit into from
Oct 28, 2020

Conversation

sarah-quinones
Copy link

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 is nothrow_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.

Copy link
Contributor

@vitaut vitaut left a 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/core.h Outdated Show resolved Hide resolved
include/fmt/core.h Outdated Show resolved Hide resolved

# define FMT_DECLTYPE_RETURN(val) \
->decltype(val) { return val; } \
static_assert(true, "a")
Copy link
Contributor

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?

Copy link
Author

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

include/fmt/ranges.h Outdated Show resolved Hide resolved
@@ -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] {
Copy link
Contributor

Choose a reason for hiding this comment

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

T const -> const T

@vitaut
Copy link
Contributor

vitaut commented Oct 28, 2020

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.

2 participants