https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120305

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to aneris from comment #0)
>     auto triangularNums = std::ranges::views::iota(1lu, N + 1) |
> std::views::transform([](long unsigned a){return (a * (a + 1))/2;}); 
>     return std::vector<long unsigned>{triangularNums.begin(),
> triangularNums.end()};

This is not a bug. The std::vector(InputIterator, InputIterator) constructor
requires arguments that meet the Cpp17InputIterator requirements.
ranges::iota_view iterators do not meet those requirements.

The correct way to do this is:

  return std::ranges::to<std::vector<long unsigned>>(triangularNums);

You can also directly use the constructor that std::ranges::to uses:

  return std::vector<long unsigned>{std::from_range, triangularNums);

The std::ranges::to solution works since GCC 14, the std::from_range
constructor is only supported since GCC 15.

Reply via email to