#pragma once #include #include #include namespace util { namespace rg = std::ranges; namespace detail { template constexpr auto get_first(R &&r) -> std::optional> { if (rg::begin(r) == rg::end(r)) { return std::nullopt; } else { return *rg::begin(r); } } struct first_range_adaptor { template constexpr auto operator()(R &&r) const { return get_first(std::forward(r)); } }; template constexpr auto operator|(R &&r, const first_range_adaptor &adaptor) { return adaptor(std::forward(r)); } } // namespace detail namespace views { inline detail::first_range_adaptor first; } template constexpr auto get_first(R &&r) -> std::optional>{ return r | views::first; } } // namespace util