Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'udpor-phase3' into 'master'
[simgrid.git] / src / xbt / utils / iter / LazyPowerset.hpp
1 /* Copyright (c) 2004-2023 The SimGrid Team. All rights reserved.           */
2
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. */
5
6 #ifndef XBT_UTILS_LAZY_POWER_SET_HPP
7 #define XBT_UTILS_LAZY_POWER_SET_HPP
8
9 #include "src/xbt/utils/iter/powerset.hpp"
10
11 namespace simgrid::xbt {
12
13 template <class Iterable> class LazyPowerset;
14 template <class Iterable> LazyPowerset<Iterable> make_powerset_iter(const Iterable& container);
15
16 /**
17  * @brief A container which "contains" all subsets of
18  * size `k` of some other container `WrapperContainer`
19  *
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
23  * some iterable type.
24  *
25  * @class Iterable: The container from which
26  * the subsets "contained" by this container are derived
27  */
28 template <class Iterable> class LazyPowerset final {
29 public:
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>(); }
32
33 private:
34   const Iterable& iterable;
35   LazyPowerset(const Iterable& iterable) : iterable(iterable) {}
36   template <class IterableType> friend LazyPowerset<IterableType> make_powerset_iter(const IterableType& iterable);
37 };
38
39 template <class Iterable> LazyPowerset<Iterable> make_powerset_iter(const Iterable& container)
40 {
41   return LazyPowerset<Iterable>(container);
42 }
43
44 } // namespace simgrid::xbt
45
46 #endif