Skip to content

Commit

Permalink
[containers] PredMapView -> MapView
Browse files Browse the repository at this point in the history
  • Loading branch information
osdeverr committed Dec 2, 2024
1 parent 8feb735 commit 2ec03a6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
3 changes: 1 addition & 2 deletions playground/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ int main()

auto strs_view = strs.ToSpan();

auto view =
strs_view.map(predicate, ".").map(&ulib::string::split, "ky"); // ulib::PredMapView{ulib::PredMapView{strs, predicate, "."}, predicate, "_"};
auto view = strs_view.map(predicate, ".").map(&ulib::string::split, "ky"); // ulib::MapView{ulib::MapView{strs, predicate, "."}, predicate, "_"};

for (auto s : view)
{
Expand Down
6 changes: 3 additions & 3 deletions ulib/ulib/containers/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -766,20 +766,20 @@ namespace ulib
for (auto it = mBegin; it != mLast; it++)
result.push_back(pred(*it, args...));
return PredMapView<SelfT, NewPred, NewArgs...>{*this, std::forward<NewPred>(pred), std::forward<NewArgs>(args)...};
return MapView<SelfT, NewPred, NewArgs...>{*this, std::forward<NewPred>(pred), std::forward<NewArgs>(args)...};
}
*/

template <class Pred, class... Args>
auto map_lazy(Pred &&pred, Args &&...args) const
{
return PredMapView<const SelfT, Pred, Args...>{*this, std::forward<Pred>(pred), std::forward<Args>(args)...};
return MapView<const SelfT, Pred, Args...>{*this, std::forward<Pred>(pred), std::forward<Args>(args)...};
}

template <class Pred, class... Args>
auto map_lazy(Pred &&pred, Args &&...args)
{
return PredMapView<SelfT, Pred, Args...>{*this, std::forward<Pred>(pred), std::forward<Args>(args)...};
return MapView<SelfT, Pred, Args...>{*this, std::forward<Pred>(pred), std::forward<Args>(args)...};
}

template <class Pred, class... Args>
Expand Down
18 changes: 9 additions & 9 deletions ulib/ulib/containers/mapview.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
namespace ulib
{
template <class SpanT, class Pred, class... Args>
class PredMapView
class MapView
{
public:
using SelfT = PredMapView<SpanT, Pred, Args...>;
using SelfT = MapView<SpanT, Pred, Args...>;

using underlying_span_type = SpanT;
using predicate_type = std::decay_t<Pred>;
Expand All @@ -28,7 +28,7 @@ namespace ulib
struct Iterator : public BaseIterator<std::remove_cv_t<value_type>, std::random_access_iterator_tag>
{
inline Iterator() {}
inline Iterator(underlying_iterator iter, const PredMapView *view) : iter(iter), view(view) {}
inline Iterator(underlying_iterator iter, const MapView *view) : iter(iter), view(view) {}

static auto TupleIterHelper(underlying_value_type &obj) { return std::make_tuple(std::ref(obj)); }

Expand Down Expand Up @@ -70,7 +70,7 @@ namespace ulib
// inline T *raw() { return ptr; }

underlying_iterator iter;
const PredMapView *view;
const MapView *view;
};

public:
Expand All @@ -79,12 +79,12 @@ namespace ulib
SpanT &underlying_span() { return mSpan; }
const SpanT &underlying_span() const { return mSpan; }

PredMapView(underlying_span_type span, predicate_type &&pred, Args... args)
MapView(underlying_span_type span, predicate_type &&pred, Args... args)
: mSpan{span}, mPred{std::move(pred)}, mArgs{std::make_tuple<std::decay_t<Args>...>(args...)}
{
}

PredMapView(underlying_span_type span, const predicate_type &pred, Args... args)
MapView(underlying_span_type span, const predicate_type &pred, Args... args)
: mSpan{span}, mPred{pred}, mArgs{std::make_tuple<std::decay_t<Args>...>(args...)}
{
}
Expand All @@ -97,21 +97,21 @@ namespace ulib
template <class NewPred, class... NewArgs>
auto map(NewPred &&pred, NewArgs &&...args) const
{
return PredMapView<SelfT, NewPred, NewArgs...>{*this, std::forward<NewPred>(pred), std::forward<NewArgs>(args)...};
return MapView<SelfT, NewPred, NewArgs...>{*this, std::forward<NewPred>(pred), std::forward<NewArgs>(args)...};
}

template <class... FuncArgs, class RetVal, class VT = value_type, class RetContValT = ulib::type_if_t<RetVal, !std::is_same_v<RetVal, void>>>
auto map(RetVal (VT::*fn)(FuncArgs &&...), FuncArgs &&...args) const
{
auto pred = [fn, ... args = std::forward<FuncArgs>(args)](VT &instance) { return ((instance).*fn)(args...); };
return PredMapView<SelfT, decltype(pred)>{*this, std::move(pred)};
return MapView<SelfT, decltype(pred)>{*this, std::move(pred)};
}

template <class... FuncArgs, class RetVal, class VT = value_type, class RetContValT = ulib::type_if_t<RetVal, !std::is_same_v<RetVal, void>>>
auto map(RetVal (VT::*fn)(FuncArgs &&...) const, FuncArgs &&...args) const
{
auto pred = [fn, ... args = std::forward<FuncArgs>(args)](const VT &instance) { return ((instance).*fn)(args...); };
return PredMapView<SelfT, decltype(pred)>{*this, std::move(pred)};
return MapView<SelfT, decltype(pred)>{*this, std::move(pred)};
}

private:
Expand Down
2 changes: 1 addition & 1 deletion ulib/ulib/containers/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ namespace ulib
template <class Pred, class... Args>
auto map(Pred &&pred, Args &&...args)
{
return PredMapView<SelfT, Pred, Args...>{*this, std::forward<Pred>(pred), std::forward<Args>(args)...};
return MapView<SelfT, Pred, Args...>{*this, std::forward<Pred>(pred), std::forward<Args>(args)...};
}

private:
Expand Down

0 comments on commit 2ec03a6

Please sign in to comment.