iterator.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_UTIL_RANGES_ITERATOR_H_
  5. #define BASE_UTIL_RANGES_ITERATOR_H_
  6. #include <iterator>
  7. namespace util {
  8. namespace ranges {
  9. // Simplified implementation of C++20's std::ranges::begin.
  10. // As opposed to std::ranges::begin, this implementation does not prefer a
  11. // member begin() over a free standing begin(), does not check whether begin()
  12. // returns an iterator, does not inhibit ADL and is not constexpr.
  13. //
  14. // Reference: https://wg21.link/range.access.begin
  15. template <typename Range>
  16. decltype(auto) begin(Range&& range) {
  17. using std::begin;
  18. return begin(std::forward<Range>(range));
  19. }
  20. // Simplified implementation of C++20's std::ranges::end.
  21. // As opposed to std::ranges::end, this implementation does not prefer a
  22. // member end() over a free standing end(), does not check whether end()
  23. // returns an iterator, does not inhibit ADL and is not constexpr.
  24. //
  25. // Reference: - https://wg21.link/range.access.end
  26. template <typename Range>
  27. decltype(auto) end(Range&& range) {
  28. using std::end;
  29. return end(std::forward<Range>(range));
  30. }
  31. } // namespace ranges
  32. } // namespace util
  33. #endif // BASE_UTIL_RANGES_ITERATOR_H_