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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This compiles OK:

namespace std::ranges
{
  template<class T, bool Sized = true>
    class subrange
    {
    private:
      template<typename, bool = Sized>
        struct _Size
        { };

      template<typename U>
        struct _Size<U, true>
        { U _M_size; };

      [[no_unique_address]] _Size<unsigned> _M_size = {};

    public:
      constexpr
      subrange(const T*, unsigned __n)
      {
        if constexpr (Sized)
          _M_size._M_size = __n;
      }

      constexpr unsigned size() const
      {
        if constexpr (Sized)
          return _M_size._M_size;
        else
          return 0;
      }
    };

  template<class T>
  constexpr int distance(subrange<T, true> const& s)
  { return s.size(); }

} // std::ranges

constexpr int i = 0;
constexpr auto r = std::ranges::subrange(&i, 1);
static_assert(std::ranges::distance(r));

Reply via email to