-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Some ranges of char are misprinted or don't compile #2634
Comments
The behavior in the first example is caused by range items becoming convertible to |
Range elements convertible to std::string line = "a,b-c,d-e,f";
fmt::print("{}\n", line | std::views::split(',')); now produces the following output in C++23 (https://godbolt.org/z/f465jEq4s):
which seems reasonable. |
The problem in the second example is caused by only partial support for non-const-iterable ranges. In particular, Line 545 in 796662a
and a few other places. A PR to improve support for non-const-iterable/formattable types would be welcome. |
Not sure I agree with this. If I'm just printing a |
|
|
Wait, what? o_O |
Most contiguous ranges of |
It's already implemented. https://godbolt.org/z/EzWr71z3c |
Yes, that's what my comment was pointing out. |
IMO, we can take Python as an analogy. If something is convertible to So, it's the way a Now assume there is a user defined string with The way a Also be very careful to change the code. Otherwise, the |
Do GCC v12.2 |
MSVC seems broken: |
Ah, the
...and with other range contrains also. MSVC
|
It's not an extension. The constructor used to be implicit, see #3030 / https://wg21.link/p2499. |
Yeah, it was temporarily implicit in a working draft but it's neither valid C++20 nor valid C++23. |
Microsoft/STL opensource side already fixes the ctor |
Item 1 now gives the same output in C++20 (https://godbolt.org/z/qhcWPer7G) and C++23 (https://godbolt.org/z/er8qzjrYx): #include <fmt/ranges.h>
#include <ranges>
int main() {
std::string line = "a,b-c,d-e,f";
fmt::print("{}\n", line | std::views::split(','));
} Output:
The only issue is that individual characters are not quoted which should be easy to fix (a PR is welcome). |
First example:
With C++20, this prints the expected/desired:
But with C++23, this prints:
This has something to do with the mapper hijacking the underlying range as a string view and then printing it unquoted. Not sure exactly.
Second example:
On C++20, this fails to compile with (this error I don't understand):
On C++23, this fails to compile for a different reason (this issue is because
core.h
checks ifstring_view
is constructible fromX
, which it is, but then tries to construct it fromconst X&
, which it's not):This example is an attempt at reducing the actually-desired:
Which fails on the ambiguous
write
call.The text was updated successfully, but these errors were encountered: