From 00b9b89bdd1db70b31079a5cf9b96c778c2af26a Mon Sep 17 00:00:00 2001 From: RobinTF <83676088+RobinTF@users.noreply.github.com> Date: Tue, 12 Nov 2024 00:47:16 +0100 Subject: [PATCH] Provide own version of owning view --- src/engine/CartesianProductJoin.cpp | 3 +- src/util/OwningView.h | 82 +++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/util/OwningView.h diff --git a/src/engine/CartesianProductJoin.cpp b/src/engine/CartesianProductJoin.cpp index f3f9e07020..0ccd465a97 100644 --- a/src/engine/CartesianProductJoin.cpp +++ b/src/engine/CartesianProductJoin.cpp @@ -5,6 +5,7 @@ #include "engine/CartesianProductJoin.h" #include "engine/CallFixedSize.h" +#include "util/OwningView.h" // ____________________________________________________________________________ CartesianProductJoin::CartesianProductJoin( @@ -157,7 +158,7 @@ ProtoResult CartesianProductJoin::computeResult(bool requestLaziness) { // Owning view wrapper to please gcc 11. return {produceTablesLazily(std::move(staticMergedVocab), - std::ranges::owning_view{std::move(subResults)} | + owning_view{std::move(subResults)} | std::views::transform(&Result::idTable), getLimit()._offset, getLimit().limitOrDefault()), resultSortedOn()}; diff --git a/src/util/OwningView.h b/src/util/OwningView.h new file mode 100644 index 0000000000..984b2d85da --- /dev/null +++ b/src/util/OwningView.h @@ -0,0 +1,82 @@ +// Copyright 2024, University of Freiburg, +// Chair of Algorithms and Data Structures. +// Author: Robin Textor-Falconi + +#pragma once + +#include + +// Implementation of std::ranges::owning_view for gcc 11. +#if __GNUC__ == 11 +#include "util/TypeTraits.h" + +template +requires std::movable && + (!ad_utility::isInstantiation, + std::initializer_list>)class owning_view + : public std::ranges::view_interface> { + private: + R range_ = R(); + + public: + owning_view() requires std::default_initializable = default; + + constexpr owning_view(R&& r) noexcept(std::is_nothrow_move_constructible_v) + : range_(std::move(r)) {} + + owning_view(owning_view&&) = default; + owning_view& operator=(owning_view&&) = default; + + constexpr R& base() & noexcept { return range_; } + + constexpr const R& base() const& noexcept { return range_; } + + constexpr R&& base() && noexcept { return std::move(range_); } + + constexpr const R&& base() const&& noexcept { return std::move(range_); } + + constexpr std::ranges::iterator_t begin() { + return std::ranges::begin(range_); + } + + constexpr std::ranges::sentinel_t end() { + return std::ranges::end(range_); + } + + constexpr auto begin() const requires std::ranges::range { + return std::ranges::begin(range_); + } + + constexpr auto end() const requires std::ranges::range { + return std::ranges::end(range_); + } + + constexpr bool empty() requires requires { std::ranges::empty(range_); } { + return std::ranges::empty(range_); + } + + constexpr bool empty() const requires requires { std::ranges::empty(range_); } + { + return std::ranges::empty(range_); + } + + constexpr auto size() requires std::ranges::sized_range { + return std::ranges::size(range_); + } + + constexpr auto size() const requires std::ranges::sized_range { + return std::ranges::size(range_); + } + + constexpr auto data() requires std::ranges::contiguous_range { + return std::ranges::data(range_); + } + + constexpr auto data() const requires std::ranges::contiguous_range { + return std::ranges::data(range_); + } +}; +#else +template +using owning_view = std::ranges::owning_view; +#endif