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_KSUBSETS_HPP
7 #define XBT_UTILS_LAZY_KSUBSETS_HPP
9 #include "src/xbt/utils/iter/subsets.hpp"
11 namespace simgrid::xbt {
13 template <class Iterable> class LazyKSubsets;
14 template <class Iterable> LazyKSubsets<Iterable> make_k_subsets_iter(unsigned k, 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 LazyKSubsets final {
32 return subsets_iterator<typename Iterable::const_iterator>(k, iterable.begin(), iterable.end());
34 auto end() const { return subsets_iterator<typename Iterable::const_iterator>(k); }
38 const Iterable& iterable;
39 LazyKSubsets(unsigned k, const Iterable& iterable) : k(k), iterable(iterable) {}
41 template <class IterableType>
42 friend LazyKSubsets<IterableType> make_k_subsets_iter(unsigned k, const IterableType& iterable);
45 template <class Iterable> LazyKSubsets<Iterable> make_k_subsets_iter(unsigned k, const Iterable& container)
47 return LazyKSubsets<Iterable>(k, container);
50 } // namespace simgrid::xbt