Skip to content

Commit

Permalink
Provide own version of owning view
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTF committed Nov 11, 2024
1 parent ce3c722 commit 00b9b89
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/engine/CartesianProductJoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "engine/CartesianProductJoin.h"

#include "engine/CallFixedSize.h"
#include "util/OwningView.h"

// ____________________________________________________________________________
CartesianProductJoin::CartesianProductJoin(
Expand Down Expand Up @@ -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()};
Expand Down
82 changes: 82 additions & 0 deletions src/util/OwningView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2024, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Author: Robin Textor-Falconi <[email protected]>

#pragma once

#include <ranges>

// Implementation of std::ranges::owning_view for gcc 11.
#if __GNUC__ == 11
#include "util/TypeTraits.h"

template <std::ranges::range R>
requires std::movable<R> &&
(!ad_utility::isInstantiation<std::remove_cv_t<R>,
std::initializer_list>)class owning_view
: public std::ranges::view_interface<owning_view<R>> {
private:
R range_ = R();

public:
owning_view() requires std::default_initializable<R> = default;

constexpr owning_view(R&& r) noexcept(std::is_nothrow_move_constructible_v<R>)
: 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<R> begin() {
return std::ranges::begin(range_);
}

constexpr std::ranges::sentinel_t<R> end() {
return std::ranges::end(range_);
}

constexpr auto begin() const requires std::ranges::range<const R> {
return std::ranges::begin(range_);
}

constexpr auto end() const requires std::ranges::range<const R> {
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<R> {
return std::ranges::size(range_);
}

constexpr auto size() const requires std::ranges::sized_range<const R> {
return std::ranges::size(range_);
}

constexpr auto data() requires std::ranges::contiguous_range<R> {
return std::ranges::data(range_);
}

constexpr auto data() const requires std::ranges::contiguous_range<const R> {
return std::ranges::data(range_);
}
};
#else
template <std::ranges::range R>
using owning_view = std::ranges::owning_view<R>;
#endif

0 comments on commit 00b9b89

Please sign in to comment.