cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[SUGGESTION] Make main args usable with ranges

Open jhugard opened this issue 5 months ago • 0 comments

While toying with hello world, noticed that cpp2:args isn't usable with std::ranges.

Suggesting to update definition to satisfy std::ranges::bidirectional_range, so that the following is possible:

main: (args) = {
    static_assert(std::bidirectional_iterator<cpp2::args::iterator>);
    static_assert(std::ranges::bidirectional_range<cpp2::args>);
    static_assert(std::ranges::viewable_range<cpp2::args>);

    // Output command line arguments, dropping the program name argc[0].
    for args | std::ranges::views::drop(1) do (arg)
    {
        std::cout
            << arg << std::endl;
    }
}

PR inbound...

jhugard avatar Sep 16 '24 22:09 jhugard