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

--- Comment #5 from Matthias Kretz (Vir) <mkretz at gcc dot gnu.org> ---
Thanks for looking into this issue!
Yes, GCC is currently the compiler that comes closest to implementing P2280 -
Clang fails on so many more examples here. However, WG21 just voted library
wording into the working draft that relies on this feature. :-)

I modified your reduced example to be closer to the original code.
(ranges::size(r) returns r.size(); integral_constant (i) is convertible to the
value, making it comparable - no need for operator==). I also added a 'size(t)
> 0' check and a check for a type that is not statically sized, where the
concept shouldn't become ill-formed either.

https://godbolt.org/z/dE6sjnaKP

```
template <int N> struct a {
  constexpr int size () const { return N; }
};

struct v {
  int _size = 3;
  constexpr int size () const { return _size; }
};

template <int N> struct i {
  constexpr operator int () const { return N; }
};

template <typename T>
constexpr auto size (T &&t) { return t.size (); }

template <typename T>
concept StaticSizedRange = requires (T &&t) {
  typename i<size(t)>;
  requires (size (t) > 0);
};

a<5> b;
static_assert (size (b) == size (b));

static_assert (StaticSizedRange<a<5>>);
static_assert (StaticSizedRange<a<5> &>);
static_assert (StaticSizedRange<const a<5> &>);

// a std::vector is not a statically sized range
static_assert (!StaticSizedRange<v>);
```

Reply via email to