Timeline for Palindrome predicate
Current License: CC BY-SA 4.0
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 17 at 14:55 | comment | added | Toby Speight |
Yes - distance() will do size() if possible (the quick way) but will fall back to counting iterations rather than failing to compile. I don't think it can avoid invoking the filter function all the way through when it counts (though perhaps std::views::filter is allowed to cache results); the transform view is a straight pass-through for advancing the iterator (it only intervenes for dereferencing), so that may well optimise out.
|
|
Jan 17 at 12:31 | comment | added | G. Sliepen | True. It might be expensive though, as it would have to go through the whole range just to get the distance to the end, which would invoke the filter and other range adapters you chain together multiple times. I wonder if that could be avoided. | |
Jan 17 at 11:17 | comment | added | Toby Speight |
Needs std::ranges::distance() rather std::ranges::size() if it's to work with non-sized ranges (such as the filter view in the tests).
|
|
Jan 17 at 8:09 | comment | added | Toby Speight |
I considered the digit_view but succumbed to premature optimisation without benchmarking! Passing base as an argument is a good idea. Good catch on the corner cases - I totally overlooked that! Thanks once again for improving my C++ competence.
|
|
Jan 17 at 8:01 | history | edited | G. Sliepen | CC BY-SA 4.0 |
added 708 characters in body
|
Jan 16 at 22:59 | history | answered | G. Sliepen | CC BY-SA 4.0 |