C++ Logo

std-proposals

Advanced search

[std-proposals] Redundant std::begin() and std::end() overloads for std::initializer_list

From: hamburger blacktea <blackteahamburger_at_[hidden]>
Date: Tue, 30 Aug 2022 13:43:00 +0000
See https://stackoverflow.com/q/25215590. That's an old question (in 2014).

So I want to solve it:


Proposed resolution:


      1. Remove 17.11.5 [support.initlist.range]:

template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
-1- Returns: il.begin().
template<class E> constexpr const E* end(initializer_list<E> il) noexcept;
-2- Returns: il.end()

      2. Modify 17.11.2 [initializer.list.syn] as indicated:

// all freestanding
namespace std {
  template<class E> class initializer_list {
  public:
    using value_type = E;
    using reference = const E&;
    using const_reference = const E&;
    using size_type = size_t;

    using iterator = const E*;
    using const_iterator = const E*;

    constexpr initializer_list() noexcept;

    constexpr size_t size() const noexcept; // number of elements
    constexpr const E* begin() const noexcept; // first element
    constexpr const E* end() const noexcept; // one past the last element
  };

  // [support.initlist.range], initializer list range access
  template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;
  template<class E> constexpr const E* end(initializer_list<E> il) noexcept;
}

I tried submitting it as a standard library issue, but the LWG chair said it needed a proposal. Can someone help?


Received on 2022-08-30 13:43:05