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

join() forces const-ness on the range which prevents it accepting some range-v3 ranges #1784

Closed
tonyelewis opened this issue Jul 18, 2020 · 4 comments

Comments

@tonyelewis
Copy link
Contributor

Thanks so much for all your fantastic work on fmt, standardisation and Tweeting.

The following attempt to combine range-v3 with fmt fails to compile under Clang or GCC (-std=c++17 -fsyntax-only) (Godbolt) :

#include <fmt/core.h>
#include <fmt/ranges.h>

#include <range/v3/view/filter.hpp>

using ::std::array;
using ::std::literals::string_literals::operator""s;
using ::std::string;

namespace views = ::ranges::views;

int main() {
    const array some_strs{ "a"s, "bb"s, "ccc"s };
    ::fmt::join(
        some_strs | views::filter(
            [] (const string &x) { return x.length() != 2; }
        )
        ,
        ""
    );
}

I'm pretty sure the problem is caused by the consts around format.h:3388. The range-v3 design involves some views (such as filter in the example above) updating internal state (eg a cached iterator) so they have const-only begin() / end(), which means a const reference to such a view is not a valid range. See "View const-ness" on https://ericniebler.github.io/range-v3/ for more info.

@vitaut
Copy link
Contributor

vitaut commented Jul 20, 2020

Thanks for the suggestion. A PR to make the range requirements more compatible with ranges-v3 would be welcome.

@tonyelewis
Copy link
Contributor Author

Thanks. I've submitted #1786 as you'll see above.

BTW, I'm seeing various test failures in GCC and under sanitizers. Are these know issues or should I submit issues for them?

@vitaut
Copy link
Contributor

vitaut commented Jul 20, 2020

Are these know issues or should I submit issues for them?

Please submit an issue.

vitaut pushed a commit that referenced this issue Jul 21, 2020
See #1784.

Add tests that demonstrate the problem and check obvious variations.
@vitaut vitaut closed this as completed Jul 21, 2020
@tonyelewis
Copy link
Contributor Author

Thanks.

chenyt9 pushed a commit to MotorolaMobilityLLC/external-fmtlib that referenced this issue May 9, 2023
See fmtlib/fmt#1784.

Add tests that demonstrate the problem and check obvious variations.
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

No branches or pull requests

2 participants