Skip to content

Commit

Permalink
Merge branch 'main' into pr/select_by
Browse files Browse the repository at this point in the history
  • Loading branch information
tcbrindle authored Jul 13, 2023
2 parents f9a2a33 + 4d6aa03 commit 583f208
Show file tree
Hide file tree
Showing 11 changed files with 400 additions and 389 deletions.
2 changes: 1 addition & 1 deletion include/flux/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

#include <flux/core/concepts.hpp>
#include <flux/core/default_impls.hpp>
#include <flux/core/functional.hpp>
#include <flux/core/inline_sequence_base.hpp>
#include <flux/core/macros.hpp>
#include <flux/core/optional.hpp>
#include <flux/core/predicates.hpp>
#include <flux/core/sequence_access.hpp>
#include <flux/core/simple_sequence_base.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef FLUX_CORE_PREDICATES_HPP_INCLUDED
#define FLUX_CORE_PREDICATES_HPP_INCLUDED
#ifndef FLUX_CORE_FUNCTIONAL_HPP_INCLUDED
#define FLUX_CORE_FUNCTIONAL_HPP_INCLUDED

#include <flux/core/macros.hpp>

Expand Down Expand Up @@ -70,6 +70,58 @@ struct proj2 {
template <typename F, typename L = std::identity, typename R = std::identity>
proj2(F, L = {}, R = {}) -> proj2<F, L, R>;

namespace detail {

template <typename Func>
struct lazy_apply {
Func func_;

template <typename Tuple>
constexpr auto operator()(Tuple&& tuple) &
noexcept(noexcept(std::apply(func_, FLUX_FWD(tuple))))
-> decltype(std::apply(func_, FLUX_FWD(tuple)))
{
return std::apply(func_, FLUX_FWD(tuple));
}

template <typename Tuple>
constexpr auto operator()(Tuple&& tuple) const&
noexcept(noexcept(std::apply(func_, FLUX_FWD(tuple))))
-> decltype(std::apply(func_, FLUX_FWD(tuple)))
{
return std::apply(func_, FLUX_FWD(tuple));
}

template <typename Tuple>
constexpr auto operator()(Tuple&& tuple) &&
noexcept(noexcept(std::apply(std::move(func_), FLUX_FWD(tuple))))
-> decltype(std::apply(std::move(func_), FLUX_FWD(tuple)))
{
return std::apply(std::move(func_), FLUX_FWD(tuple));
}

template <typename Tuple>
constexpr auto operator()(Tuple&& tuple) const&&
noexcept(noexcept(std::apply(std::move(func_), FLUX_FWD(tuple))))
-> decltype(std::apply(std::move(func_), FLUX_FWD(tuple)))
{
return std::apply(std::move(func_), FLUX_FWD(tuple));
}
};

struct unpack_fn {
template <typename Func>
constexpr auto operator()(Func&& func) const
-> lazy_apply<std::decay_t<Func>>
{
return lazy_apply<std::decay_t<Func>>{.func_ = FLUX_FWD(func)};
}
};

} // namespace detail

inline constexpr auto unpack = detail::unpack_fn{};

namespace pred {

namespace detail {
Expand Down
98 changes: 11 additions & 87 deletions include/flux/op/read_only.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,108 +13,32 @@ namespace flux {

namespace detail {

template <typename T>
struct cast_to_const {
constexpr auto operator()(auto&& elem) const -> T { return FLUX_FWD(elem); }
};

template <sequence Base>
requires (not read_only_sequence<Base>)
struct read_only_adaptor : inline_sequence_base<read_only_adaptor<Base>> {
struct read_only_adaptor : map_adaptor<Base, cast_to_const<const_element_t<Base>>> {
private:
FLUX_NO_UNIQUE_ADDRESS Base base_;
using map = map_adaptor<Base, cast_to_const<const_element_t<Base>>>;

public:
constexpr read_only_adaptor(decays_to<Base> auto&& base)
: base_(FLUX_FWD(base))
constexpr explicit read_only_adaptor(decays_to<Base> auto&& base)
: map(FLUX_FWD(base), cast_to_const<const_element_t<Base>>{})
{}

struct flux_sequence_traits {
private:
using const_rvalue_element_t = std::common_reference_t<
value_t<Base> const&&, rvalue_element_t<Base>>;

public:
struct flux_sequence_traits : map::flux_sequence_traits {
using value_type = value_t<Base>;

static constexpr auto first(auto& self) -> cursor_t<Base> { return flux::first(self.base_); }

static constexpr auto is_last(auto& self, cursor_t<Base> const& cur) -> bool
{
return flux::is_last(self.base_, cur);
}

static constexpr auto inc(auto& self, cursor_t<Base>& cur) -> void
{
flux::inc(self.base_, cur);
}

static constexpr auto read_at(auto& self, cursor_t<Base> const& cur)
-> const_element_t<Base>
{
return static_cast<const_element_t<Base>>(flux::read_at(self.base_, cur));
}

static constexpr auto read_at_unchecked(auto& self, cursor_t<Base> const& cur)
-> const_element_t<Base>
{
return static_cast<const_element_t<Base>>(flux::read_at_unchecked(self.base_, cur));
}

static constexpr auto move_at(auto& self, cursor_t<Base> const& cur)
-> const_rvalue_element_t
{
return static_cast<const_rvalue_element_t>(flux::move_at(self.base_, cur));
}

static constexpr auto move_at_unchecked(auto& self, cursor_t<Base> const& cur)
-> const_rvalue_element_t
{
return static_cast<const_rvalue_element_t>(flux::move_at_unchecked(self.base_, cur));
}

static constexpr auto last(auto& self) -> cursor_t<Base>
requires bounded_sequence<Base>
{
return flux::last(self.base_);
}

static constexpr auto dec(auto& self, cursor_t<Base>& cur)
requires bidirectional_sequence<Base>
{
return flux::dec(self.base_, cur);
}

static constexpr auto inc(auto& self, cursor_t<Base>& cur, distance_t o)
requires random_access_sequence<Base>
{
return flux::inc(self.base_, cur, o);
}

static constexpr auto distance(auto& self, cursor_t<Base> const& from,
cursor_t<Base> const& to) -> distance_t
requires random_access_sequence<Base>
{
return flux::distance(self.base_, from, to);
}

static constexpr auto size(auto& self) -> distance_t
requires sized_sequence<Base>
{
return flux::size(self.base_);
}

static constexpr auto data(auto& self)
requires contiguous_sequence<Base>
{
using P = std::add_pointer_t<std::remove_reference_t<const_element_t<Base>>>;
return static_cast<P>(flux::data(self.base_));
}

static constexpr auto for_each_while(auto& self, auto&& pred)
{
return flux::for_each_while(self.base_, [&pred](auto&& elem) {
return std::invoke(pred, static_cast<const_element_t<Base>>(FLUX_FWD(elem)));
});
return static_cast<P>(flux::data(self.base()));
}
};


};

struct read_only_fn {
Expand Down
4 changes: 2 additions & 2 deletions include/flux/op/set_adaptors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ struct set_union_adaptor
bounded_sequence<Base1> && bounded_sequence<Base2>
static constexpr auto last(Self& self) -> cursor_type
{
return cursor_type{flux::last(self.base1_), flux::last(self.base2_)};
return cursor_type{flux::last(self.base1_), flux::last(self.base2_), cursor_type::second};
}

template <typename Self>
Expand Down Expand Up @@ -558,4 +558,4 @@ inline constexpr auto set_intersection = detail::set_intersection_fn{};

} // namespace flux

#endif // namespace FLUX_OP_SET_ADAPTORS_HPP_INCLUDED
#endif // namespace FLUX_OP_SET_ADAPTORS_HPP_INCLUDED
Loading

0 comments on commit 583f208

Please sign in to comment.