constexpr.cc 655 B

1234567891011121314151617181920212223242526
  1. // { dg-options "-std=gnu++20" }
  2. // { dg-do compile { target c++20 } }
  3. #include <ranges>
  4. struct iterator
  5. {
  6. using difference_type = int;
  7. int i;
  8. int operator*() const { return i; }
  9. // These are intentionally not constexpr:
  10. iterator& operator++() { ++i; return *this; }
  11. iterator operator++(int) { return {i++}; }
  12. bool operator==(const iterator& it) const { return i == it.i; }
  13. };
  14. constexpr iterator begin(1), end(2);
  15. using std::ranges::subrange;
  16. using std::ranges::subrange_kind;
  17. // This used to fail due to using operator++ and operator== in an assertion:
  18. constexpr subrange<iterator, iterator, subrange_kind::sized> s(begin, end, 1);