1 /* Copyright (c) 2004-2023 The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef XBT_UTILS_LAZY_POWER_SET_HPP
7 #define XBT_UTILS_LAZY_POWER_SET_HPP
9 #include "src/xbt/utils/iter/powerset.hpp"
11 namespace simgrid::xbt {
13 template <class Iterable> class LazyPowerset;
14 template <class Iterable> LazyPowerset<Iterable> make_powerset_iter(const Iterable& container);
17 * @brief A container which "contains" all subsets of
18 * size `k` of some other container `WrapperContainer`
20 * @note: You should not store instances of this class directly,
21 * as it acts more like a simply wrapping around another iterable
22 * type to make it more convenient to iterate over subsets of
25 * @class Iterable: The container from which
26 * the subsets "contained" by this container are derived
28 template <class Iterable> class LazyPowerset final {
30 auto begin() const { return powerset_iterator<typename Iterable::const_iterator>(iterable.begin(), iterable.end()); }
31 auto end() const { return powerset_iterator<typename Iterable::const_iterator>(); }
34 const Iterable& iterable;
35 LazyPowerset(const Iterable& iterable) : iterable(iterable) {}
36 template <class IterableType> friend LazyPowerset<IterableType> make_powerset_iter(const IterableType& iterable);
39 template <class Iterable> LazyPowerset<Iterable> make_powerset_iter(const Iterable& container)
41 return LazyPowerset<Iterable>(container);
44 } // namespace simgrid::xbt