From 6582744db5a014857b7a914815b147e88adead81 Mon Sep 17 00:00:00 2001 From: Maxwell Pirtle Date: Mon, 6 Mar 2023 14:41:24 +0100 Subject: [PATCH] Write LazyPowerSet in terms of iterator_wrapper --- src/xbt/utils/iter/LazyPowerset.hpp | 35 +++++------------------- src/xbt/utils/iter/iterator_wrapping.hpp | 8 +++--- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/src/xbt/utils/iter/LazyPowerset.hpp b/src/xbt/utils/iter/LazyPowerset.hpp index 76d348353d..5d4a07edd2 100644 --- a/src/xbt/utils/iter/LazyPowerset.hpp +++ b/src/xbt/utils/iter/LazyPowerset.hpp @@ -6,39 +6,18 @@ #ifndef XBT_UTILS_LAZY_POWER_SET_HPP #define XBT_UTILS_LAZY_POWER_SET_HPP +#include "src/xbt/utils/iter/iterator_wrapping.hpp" #include "src/xbt/utils/iter/powerset.hpp" namespace simgrid::xbt { -template class LazyPowerset; -template LazyPowerset make_powerset_iter(const Iterable& container); - -/** - * @brief A container which "contains" all subsets of - * size `k` of some other container `WrapperContainer` - * - * @note: You should not store instances of this class directly, - * as it acts more like a simply wrapping around another iterable - * type to make it more convenient to iterate over subsets of - * some iterable type. - * - * @class Iterable: The container from which - * the subsets "contained" by this container are derived - */ -template class LazyPowerset final { -public: - auto begin() const { return powerset_iterator(iterable.begin(), iterable.end()); } - auto end() const { return powerset_iterator(); } - -private: - const Iterable& iterable; - LazyPowerset(const Iterable& iterable) : iterable(iterable) {} - template friend LazyPowerset make_powerset_iter(const IterableType& iterable); -}; - -template LazyPowerset make_powerset_iter(const Iterable& container) +template +using LazyPowerset = iterator_wrapping, Args...>; + +template constexpr auto make_powerset_iter(const Iterable& container) { - return LazyPowerset(container); + return make_iterator_wrapping>(container.begin(), + container.end()); } } // namespace simgrid::xbt diff --git a/src/xbt/utils/iter/iterator_wrapping.hpp b/src/xbt/utils/iter/iterator_wrapping.hpp index e4a4ea95c7..c6d2c9572a 100644 --- a/src/xbt/utils/iter/iterator_wrapping.hpp +++ b/src/xbt/utils/iter/iterator_wrapping.hpp @@ -43,10 +43,10 @@ private: iterator_wrapping(Args&&... begin_iteration) : m_args(std::forward>(begin_iteration)...) {} template - friend iterator_wrapping make_iterator_wrapping(Arguments&&... args); + friend constexpr iterator_wrapping make_iterator_wrapping(Arguments&&... args); template - friend iterator_wrapping make_iterator_wrapping_explicit(Arguments... args); + friend constexpr iterator_wrapping make_iterator_wrapping_explicit(Arguments... args); public: iterator_wrapping(const iterator_wrapping&) = delete; @@ -62,13 +62,13 @@ public: }; template -iterator_wrapping make_iterator_wrapping(Args&&... args) +constexpr iterator_wrapping make_iterator_wrapping(Args&&... args) { return iterator_wrapping(std::forward(args)...); } template -iterator_wrapping make_iterator_wrapping_explicit(Args... args) +constexpr iterator_wrapping make_iterator_wrapping_explicit(Args... args) { return iterator_wrapping(std::forward(args)...); } -- 2.20.1