Thanks to visit codestin.com
Credit goes to github.com

Skip to content

<ranges>: list-initialization is misused #3014

@hewillk

Description

@hewillk

Non-list-initialization (parentheses) and list-initialization (curly braces) styles are mixed in the <ranges>, however, the latter does not provide any observable benefit and may bring potential issues.
We should use non-list-initialization consistently, as the standard does.

#include <ranges>
#include <initializer_list>
#include <utility>

struct I {
  using difference_type = int;
  using value_type = int;
  I(std::initializer_list<int*>) = delete;
  I(int*);
  int operator*() const;
  I& operator++();
  I operator++(int);
};

struct R {
  int* begin();
  I begin() const;
  std::unreachable_sentinel_t end() const;
};

int main() {
  auto r = R{} | std::views::transform(std::identity{});
  decltype(std::as_const(r).begin()) c = r.begin();
}

https://godbolt.org/z/89eo678qd

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!rangesC++20/23 ranges

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions